-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmap.js
More file actions
21 lines (20 loc) · 663 Bytes
/
map.js
File metadata and controls
21 lines (20 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** Polyfill for Array.prototype.map()
* let new_array = arr.map(function callback( currentValue[, index[, array]]) {
* return element for new_array
* }[, thisArg])
* */
if(!Array.prototype.map) {
Array.prototype.map = function(callback, thisArg) {
if(this === null) {
throw new TypeError('this is null or not defined');
}
if(typeof callback !== 'function') {
throw new TypeError('callback is not a function');
}
var result = [];
for(var i = 0; i < this.length; i++) {
result.push(callback.call(thisArg, this[i], i, this));
}
return result;
}
}