Created
March 12, 2017 16:58
-
-
Save Kolenov/b28f2df89a40d74f2e9007e40774d693 to your computer and use it in GitHub Desktop.
Array methods
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 forEach(arr, func){ | |
"use strict"; | |
for (var i=0, len = arr.length; i<len; i++){ | |
arr[i] = func(arr[i]); | |
} | |
} | |
function every(arr, func){ | |
"use strict"; | |
var res = null; | |
for (var i=0, len = arr.length; i<len; i++){ | |
res = res && func(arr[i]); | |
} | |
return res; | |
} | |
function some(arr, func){ | |
"use strict"; | |
var res = null; | |
for (var i=0, len = arr.length; i<len; i++){ | |
res = res || func(arr[i]); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function forEach(arr, func){
"use strict";
for (var i=0, len = arr.length; i<len; i++){
arr[i] = func(arr[i]);
}
}
function every(arr, func){
"use strict";
var res = null;
for (var i=0, len = arr.length; i<len; i++){
res = res && func(arr[i]);
}
return res;
}
function some(arr, func){
"use strict";
var res = null;
for (var i=0, len = arr.length; i<len; i++){
res = res || func(arr[i]);
}
return res;
}
function map(arr, func){
"use strict";
var res = [];
for (var i=0, len = arr.length; i<len; i++){
res[i] = func(arr[i]);
}
return res;
}
function filter(arr, func){
"use strict";
var res = [];
for (var i=0, len = arr.length; i<len; i++){
if (func(arr[i]) === true){
res.push(arr[i]);
}
}
return res;
}