map
Array.prototype.newMap = function(callback) {
const result = []
for(let i=0;i<this.length;i++) {
if(!this.hasOwnProperty(i)) {
continue;
}
result.push(callback(this[i],i,this))
}
return reuslt
}
const array = [1,2,3]
const map = array.newMap((item)=> item*3)
filter
Array.prototype.newFilter = function(callback) {
const result = []
for(let i=0;i<this.length;i++) {
if(!this.hasOwnProperty(i)) {
continue;
}
if(callback(this[i],i,this)) {
result.push(this[i])
}
}
return reuslt
}
const array = [1,2,3]
const filter = array.newFilter ((item)=> item>2)
find
Array.prototype.newFind = function(callback) {
let result;
for(let i=0;i<this.length;i++) {
if(!this.hasOwnProperty(i)) {
continue;
}
if(callback(this[i],i,this)) {
result = this[i];
break;
}
}
return reuslt
}
const array = [1,2,3]
const filter = array.newFind((item)=> item>2)
every
Array.prototype.newEvery = function(callback) {
let result = true
for(let i=0;i<this.length;i++) {
if(!this.hasOwnProperty(i)) {
continue;
}
if(!callback(this[i],i,this)) {
result = false
break;
}
}
return reuslt
}
const array = [1,2,3]
const map = array.newEvery ((item)=> item>1)
some
Array.prototype.newSome = function(callback) {
let result = false
for(let i=0;i<this.length;i++) {
if(!this.hasOwnProperty(i)) {
continue;
}
if(callback(this[i],i,this)) {
result = true
break;
}
}
return reuslt
}
const array = [1,2,3]
const map = array.newSome ((item)=> item>1)