Need help with arrow function

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) )
}

The callback function for .map() is executed on every element of the array. You need something to call “the current array element” (the equivalent of arr[i] in a for loop). In your example, you are calling it x.

this is a function, which is used as argument of map, the parameter of this function can be named in any way you want, but using arr would be really confusing as x takes value, one at a time, of each element of the array

That clears things up, thank you!

Thank you for the explanation!