5
[IT 邦帮忙] 优化或重写方法,使计算长字符串时尽可能缩短运算时间
source link: https://www.v2ex.com/t/788339
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
如果 str1 包含 str2 的所有字母(包括数量),为真,反之为假
function scramble(str1, str2) {
let s1 = str1.split("").sort()
let s2 = str2.split("").sort()
let n = 0
s2.forEach(e=>{
let index = s1.indexOf(e)
if(index>-1){
n++
s1.splice(index,1)
}
})
if(n==s2.length && n!=0){
return true
}else{
return false
}
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK