Skip to content

Instantly share code, notes, and snippets.

@renzhezhilu
Created October 10, 2019 03:25
Show Gist options
  • Save renzhezhilu/7c539c5bbbddc03ded382053acdf49f5 to your computer and use it in GitHub Desktop.
Save renzhezhilu/7c539c5bbbddc03ded382053acdf49f5 to your computer and use it in GitHub Desktop.
[提取图片array前缀] #压缩文件
//提取图片前缀
function findExactlyString(arr) {
if (arr.length <= 1) return {
leg: 0,
str: '',
diffArr: arr
}
let leg = 0
let arr00 = arr[0]
for (let i = 0; i < arr00.length; i++) {
if (arr.every(x => x[i] == arr00[i])) {
leg++
} else {
break
}
}
let diffArr = arr.map(x => x.substr(leg, x.length))
return {
leg: leg,
str: arr00.substr(0, leg),
diffArr
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment