Hello ,
I have been studying this code and would like some clarification on arrow functions.
Lets say we have an array of
[5, 7, 8, 2, 1]
and would like to divide it by a number, using the map method to give us a new array with the remainders. So if we divide [5, 7, 8, 2, 1]
by 2,
it should give us [1, 1, 0, 0, 1]
.
This is the code I have so far, and it seems to work. My question is… You’re calling the map method onto the “arr” parameter correct? So why do I have to create a new variable x
when using the arrow function? Why can’t I use
(arr => (arr % num))
??
What exactly does the x
variable “do”?
function mysteryFunc(arr, num) {
return arr.map(x => (x % num) )
}