The concept of the map function can be traced back to its roots in functional programming principles (https://en.wikipedia.org/wiki/Functional_programming). In the realm of this programming paradigm, the use of "pure functions" is emphasized, which are functions that do not alter any of their arguments.
Therefore, it's more of a deliberate decision than just an abstraction:
- Do you wish to modify your arguments directly? Alter the array in real-time
- Would you prefer a modified version of your data without changing the original? Opt for map
In certain scenarios, preserving the integrity of the original data is crucial, making map a suitable choice by default.
Alternatively, there may be situations where you have the freedom to choose. Utilizing map offers the benefit of minimizing potential side-effects (e.g., other parts of the application sharing the same array and not anticipating alterations), albeit at the expense of duplicating data.
Hence, neither option is inherently superior; it ultimately hinges on the specific objectives you aim to achieve.