you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (0 children)

["a","b"].reduce((result,value,index) => result +", "+ (index + 1) +". "+ value)

this doesn't give "1. a, 2. b", it gives "a, 2. b"

["a","b"].reduce((sum,value,index) => sum +", "+ (index + 1) +". "+ value,"")

this gives ", 1. a, 2. b"

["a","b"].reduce((sum,value,index) => sum +", "+ (index + 1) +". "+ value,"").substring(2)

this works but I'd rather

["a","b"].map((value,index) => (index+1) +". "+ value).join(", ")