(SOLVED IN post #2 and #5)
After doing some tweaking from the solution provided in here.
I came out with this similar solution, but slightly different form.
the problem is I kinda understand it but I’m not sure if it’s right or not.
Regarding 1: `Could anybody explain to me what happened and what’s the different between the two?``
The main difference is that you are allocating a new object on each iteration, to then return it from the map function. Which is totally redundant.
Also it’s an “anti pattern” in functional programming. One of the core pillar of FP is to avoid side effects, so functions that changes something outside their scope.
In your case your function keep changing the value of newMovie, which is not desired at all.
Thank you for your answer about destructuring assignment.
I still don’t understand it.
aren’t both doing a loop and returned a new object?
could you explain it further?
*revision: oh wait.
Do you mean because the map should be have returned an array of objects, but I still create a new variable to contain an array that contain the same things as what is returned by map, so I actually kinda get 2 arrays. So, my code became redundant?
Has a completely redundant variable newMovie that you assign a value to then immediately return. You can just return the value, you’re not doing anything at all with that newMovie variable – it’s just complicating the code and introducing a side effect. ie literally just doing this: