filter
const filter = (arr, fn) => {
const result = [];
for(let value of arr) {
if(fn(value)) {
result.push(value);
}
}
return result;
}
forEach
const forEach = (arr, fn) => {
for(let value of arr) {
fn(value)
}
}
map
const map = (arr, fn) => {
const result = [];
for(let value of arr) {
result.push(fn(value));
}
return result;
}
some
const some = (arr, fn) => {
let bool = false;
for(let value of arr) {
bool = fn(alue);
if(bool) {
break;
}
}
return bool;
}
every
const every = (arr, fn) => {
let bool = true;
for(let value of arr) {
bool = fn(value);
if(!bool) {
break;
}
}
return bool;
}
once
const once = (fn) => {
let done = false;
return function() {
if (!done) {
done = true;
fn.apply(fn, arguments);
}
}
}