You can just do:
['truck', 'car', 'people'].reduce((text, word) => `${text}-${word}`) > "truck-car-people"
If no initial variable is given (your first example had '') then it just pulls from the input, in this case, 'truck'
''
'truck'
You (obviously) need an initial value if the array is empty or you get a very descriptive error:
[3, 2.1, 5, 8].reduce((total, number) => total + number, 0) > 18.1 [3, 2.1, 5, 8].reduce((total, number) => total + number) > 18.1 [].reduce((total, number) => total + number, 0) > 0 [].reduce((total, number) => total + number) > VM158:1 Uncaught TypeError: Reduce of empty array with no initial value
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can just do:
If no initial variable is given (your first example had
''
) then it just pulls from the input, in this case,'truck'
You (obviously) need an initial value if the array is empty or you get a very descriptive error: