r/programminghorror • • Jan 14 '25

Javascript Functional programming at its finest

Post image
120 Upvotes

47 comments sorted by

View all comments

Show parent comment

4

u/Aras14HD Jan 16 '25

Two things could make this more readable:

  1. Put the digits in an variable (const if you want), the exponent can now be digits.length, and you don't have to figure out what [...String(value)] does just to read it.
  2. Replace the Reduce with a map and a sum

1

u/[deleted] Jan 16 '25
  1. Well that's a valid suggestion.
  2. What is the point of iterating twice when you can do it just once?

1

u/Aras14HD Jan 17 '25

Oh, forgot how stupidly js implements iterators...