-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
排序面试题 #1
Comments
arr.flat(Infinity) |
var arrTarget = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10];
function arrFlatten(arr){
let tempIdx=-1,tempItem=null;
while (arr.some((item,idx)=>{
tempIdx = idx; tempItem=item;return Array.isArray(item)
})){
arr.splice(tempIdx,1);
arr = [...tempItem,...arr];
}
return Array.from(new Set(arr));
}
let result = arrFlatten(arrTarget).sort(); |
最精简答案 只有一行
const ary = [[1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14]]]], 10]
console.log('ary', [... new Set(ary.flat(Infinity))].sort((a, b) => a - b)) |
var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
面试题,var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10];转化为 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] 请用不超过五行代码处理
The text was updated successfully, but these errors were encountered: