nishantwrp / gsoc-organizations

A site for viewing and analyzing the info of the organizations participating in Google Summer of Code.
https://www.gsocorganizations.dev
GNU General Public License v3.0
331 stars 45 forks source link

Use Array.prototype.reduce() instead of map() #99

Closed Rohitrky2021 closed 1 year ago

Rohitrky2021 commented 1 year ago

Use Array.prototype.reduce() instead of map() Using Array.prototype.reduce() instead of Array.prototype.map() can reduce the number of iterations over the array and make the code more efficient:

Rohitrky2021 commented 1 year ago

Use Array.prototype.reduce() instead of map() make the code more efficient:

nishantwrp commented 1 year ago

Hey @Rohitrky2021, I don't understand how using reduce here is more efficient than using map. You might want to go through this stackoverflow question.

Rohitrky2021 commented 1 year ago

if modifying the original array is not a concern and the goal is to return a single value after iterating over the array, then using the reduce method as in the first function might be a more concise approach.the map method is more efficient in terms of performance, but the choice between the two ultimately depends on the specific needs of the implementation.

nishantwrp commented 1 year ago

map is better for this usecase, hence closing this pr.

if modifying the original array is not a concern

We're not changing the original array in any approach.

return a single value after iterating over the array

we want array of objects (one for each element in the original array)

nishantwrp commented 1 year ago

However, if you're interested to contribute more to this project, please let me know. There are a couple of enhancements that I have in mind.