NOTE: DO NOT USE THE BUILT IN METHODS WHEN ASKED TO MAKE THEM!
-
Using Array.prototype add a new method
myForEach
that mimics the behaivor of the built inforEach
. -
Use your
myForEach
to addmyMap
to the Array prototype.myMap
should behave the same as regularmap
. -
Write a 'myFilter
that behave's the same as
filter`. -
Write a
myEvery
. -
Write a
myReduce
. It should use the first element in the array if none is given. -
Write a
myTranspose
. This function should transpose a matrix. Exp:
let mtx = [
[1, 2],
[3, 4],
[5, 6]
]
mtx.myTranspose();
// => [
[1, 3, 5],
[2, 4, 6]
]
- Use
myMap
to build a new array where every element is incremented by 10. - Use
myMap
to build a new array where every non-string element is converted to an empty string. - Use
myFilter
to get only the even elements in an array. - Use
myEvery
to check if all elements in the array are the same. - Use
myReduce
to return the sum of every element in an array. - Use
myMap
to build a new array that doubles each element. Then chainmyReduce
to find the product of all the elements. - Use
myReduce
to find the largest number in an array. - Write a function
elementDivisibleBy
with parametersdivisor
andarr
. UsemyFilter
to return a new array of every element of arr that can be evenly divided by divisor. - Write a
myJoin
function. - Write a
mySlice
function. - Write a function
countZeroes
, which takes an array of numbers as its argument and returns the amount of zeroes that occur in it. Use reduce. - Write a
numberTimesIdx
that usesmap
and multiples each number in the array by it's index.
Bonus: Write a myFlatten
. This should take a multi-dimensional array and return it as one array.
let arr = [1, 2, [3, 4, 5, [6, 7, 8]]]
arr.myFlatten();
// => [1, 2, 3, 4, 5, 6, 7, 8]