2019 阿里巴巴前端笔试题 All In One
2019 阿里巴巴前端笔试题 All In One
online REPL
https://repl.it/languages/javascript
Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
- flat nested array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
join, return String
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
concat, return Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
let arr = [1, [[2, [21, 22]], 3, 4], 5];
// repl bug
// arr.flat(3);
const expandArr = (arr) => {
let result = [];
arr.map(item => {
if(!Array.isArray(item)) {
result.push(item);
} else {
let tempArr = expandArr(item);
// result = result.join(tempArr);
result = result.concat(tempArr);
}
});
return result;
};
expandArr(arr);
Array.flat(Infinity)
FEIQA
Front End Interviews Question & Answers
https://github.com/xgqfrms/FEIQA
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/10954098.html
未经授权禁止转载,违者必究!