-
Notifications
You must be signed in to change notification settings - Fork 18
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
[js]不使用loop,创建一个长度为100的数组 #19
Comments
var arr = new Array(100); |
@mumuy 恭喜中陷阱,你可以在浏览器运行下哦,会得到一个元素全是undefined的数组 😄 |
用递归 |
看来我确实弱爆了 |
Array(100).join(",").split(",").map(function(key,index){return index;}) |
收集下A神的: Array.apply(null, {length: 10}).map(Number.call, Number) 我改一下: Object.keys(Array.apply(null, {length: 10})) |
``Array.from({length:100} , function(value, index){ return index }) |
|
Object.keys(Array(100).toString().split(",")) |
|
function genArr(i, arr){
if(i < 10){
arr[i] = i++
return genArr(i, arr);
} else {
return arr;
}
}
var arr = genArr(0, []) |
|
[...Array(10).keys()] |
Array(100).fill().map((v, i) => i) |
[...Array(100).keys()] |
不使用loop循环,创建一个长度为100的数组,并且每个元素的值等于它的下标
从某站看到的一道淘宝笔试题,挺有趣的,大家有兴趣可以做一做
😄 建议自行完成哦别搜索,不然就直接找到答案了
The text was updated successfully, but these errors were encountered: