Skip to content

Instantly share code, notes, and snippets.

@pietgeursen
Last active January 25, 2016 04:08
Show Gist options
  • Save pietgeursen/3969ee467bb71ecaef38 to your computer and use it in GitHub Desktop.
Save pietgeursen/3969ee467bb71ecaef38 to your computer and use it in GitHub Desktop.
array methods
'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