Created
October 10, 2019 03:25
-
-
Save renzhezhilu/7c539c5bbbddc03ded382053acdf49f5 to your computer and use it in GitHub Desktop.
[提取图片array前缀] #压缩文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//提取图片前缀 | |
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