const test = [
'https://mms.pinduoduo.com/home/',
'https://mms.pinduoduo.com/other/mail/mailList?spm=…_url=aHR0cHM6Ly9tbXMucGluZHVvZHVvLmNvbS9ob21lLw==',
'https://mms.pinduoduo.com/other/mail/mailList?type=-1',
'https://mms.pinduoduo.com/other/mail/mailList',
'https://mms.pinduoduo.com/home/',
'https://mms.pinduoduo.com/other/mail/mailList?spm=…_url=aHR0cHM6Ly9tbXMucGluZHVvZHVvLmNvbS9ob21lLw==',
'https://mms.pinduoduo.com/other/mail/mailList?type=-1',
'https://mms.pinduoduo.com/other/mail/mailList',
'https://mms.pinduoduo.com/home/',
'https://mms.pinduoduo.com/other/mail/mailList?spm=…_url=aHR0cHM6Ly9tbXMucGluZHVvZHVvLmNvbS9ob21lLw==',
'https://mms.pinduoduo.com/other/mail/mailList?type=-1',
'https://mms.pinduoduo.com/other/mail/mailList',
]
// 去重
const uniqueUrl = (arr: string[]) => {
let newArr: string[] = []
let len = arr.length
for (let i = 0; i < len; i++) {
if (i === 0) {
newArr.push(arr[i])
continue
}
let pre = arr[i - 1].split('?')
let after = arr[i].split('?')
if (pre[0] === after[0]) {
newArr[newArr.length - 1] = arr[i]
} else {
newArr.push(arr[i])
}
}
return newArr
}
console.log(uniqueUrl(test))
方法
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 每年到这个时候,身边就会有很多人开始咳嗽、咳痰、流鼻涕、打喷嚏的,有些是感冒、有些是哮喘、有些是气管炎,有些的鼻炎...
- 这8种学生永远拿不到高分!早看早受益! 下面是一位资深班主任总结了8种成绩提不上去的原因,分别对应8类孩子,如果你...
- 这8种学生永远拿不到高分!早看早受益! 下面是一位资深班主任总结了8种成绩提不上去的原因,分别对应8类孩子,如果你...
- 怎样反思自己的教学——学习杜威《我们怎样思维》有感 2015-01-13 14:56:52 来源:普宁市第三中学网...