Last active
April 21, 2020 16:45
-
-
Save haikelfazzani/6c6fb1e1cbe847b6ea796f3ae5d42c22 to your computer and use it in GitHub Desktop.
javascript array map method for old browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function map(a, cb) { | |
var res = []; | |
for (var i = 0, l = a.length; i < l; i++) { | |
res.push(cb(a[i], i, a)); | |
} | |
return res; | |
}; | |
// Example : | |
let r = map([1,2,3], function (value, index, array) { | |
return value*2; | |
}) | |
console.log(r) | |
// [ 2, 4, 6 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment