Open yym-yumeng123 opened 7 years ago
function map(list,iteratee){
var result = []
for(var index = 0; index < list.length; index++){
result[index] = iteratee(list[index],index)
}
return result
}
var result = map([1,2,3,4],function(num){return num *4})
console.log(result)
通过对list里的每个元素调用转换函数(iteratee迭代器)生成一个与之相对应的数组.iteratee传递三个参数:value,然后是迭代index.