Last active
January 25, 2016 04:08
-
-
Save pietgeursen/3969ee467bb71ecaef38 to your computer and use it in GitHub Desktop.
array methods
This file contains hidden or 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
'use strict' | |
class MyArray { | |
constructor(arr){this.arr = arr} | |
filter(shouldKeepFunc){ | |
let newArray = [] | |
for (let i = 0; i < this.arr.length; i++) { | |
let item = this.arr[i] | |
if(shouldKeepFunc(item)){ | |
newArray.push(item) | |
} | |
} | |
return newArray | |
} | |
map(mapperFunc){ | |
let newArray = [] | |
for (let i = 0; i < this.arr.length; i++) { | |
let item = this.arr[i] | |
newArray.push(mapperFunc(item)) | |
} | |
return newArray | |
} | |
forEach(mapperFunc){ | |
for (let i = 0; i < this.arr.length; i++) { | |
let item = this.arr[i] | |
mapperFunc(item) | |
} | |
} | |
} | |
} | |
module.exports = MyArray |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment