输入:
cap
to
cat
card
two
too
up
boat
boot
输出:
boat
boot
cap
card
cat
to
too
two
up
实现:
let arr = [就那些单词作为数组]
arr.sort(function(a,b){
let minlength = Math.min(a.length,b.length);
for(let i=0;i<minlength;i++){
if(a[i]>b[i]){
return 1
}else if(a[i]<b[i]){
return -1
}
}
if(a.length>b.length){
return 1
}else if(a.length<b.length){
return -1
}else{
return 0
}
})
arr.map(function(item){
console.log(item)
})
网友评论