A la node.js
let map = function(input,callback){
let results = [],
handleIterationResult = function(error,result){
if (error) {callback(error); return;}
results.push(result);
if (results.length === input.length){
callback(null,results);
}
};
input.forEach(function(num){
sum(num,handleIterationResult);
});
};
let sum = function (num, callback){
callback(null, num + num);
};
map([2,4,1], function (error,result){
if (error) {console.error(error);return; };
console.log(result);
});
Inscription à :
Articles (Atom)