Skip to content

Instantly share code, notes, and snippets.

@youxiachai
Created May 29, 2014 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youxiachai/ccdcffc2fb2aa7fb9e6c to your computer and use it in GitHub Desktop.
Save youxiachai/ccdcffc2fb2aa7fb9e6c to your computer and use it in GitHub Desktop.
js 数组练习
var newArray = ['1','2','3','4'].map(function (item){
return item
}).reduce(function (x, y){
if(Array.isArray(x)){
return x.concat(y)
}else{
var arr = [];
arr.push(x)
return arr;
}
}).filter(function (z) {
return z;
})
console.log(newArray)
@ylxs90
Copy link

ylxs90 commented May 29, 2014

欺负我没见过这几个方法?fuck

@youxiachai
Copy link
Author

@ylxs90 有人留言好高兴啊... 笑哥..看懂这几行代码没..js 数组普通使用..

@youxiachai
Copy link
Author

js reduce 的使用.. 问 x1 打印结果

var x1 = [1,2,3,4,5].reduce(function (x, y){
   return x+y;
})

console.log(x1);

提示:
reduce 的定义 x,y:x+y

((((1+2)+3)+4)+5)

@actionliang
Copy link

表示还需要努力

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment