Don't forget reduce :)
reduce
const items = ['a','b','c','a','a','d','b','d','d','c']; function removeDuplicates (arr){ return arr.reduce((acc, curr) => acc.includes(curr) ? acc : [...acc, curr], []); }
I was surprised this was not included :-)
Can't figure out, what does [], in itterable condition
The reduce function uses and accumulator as part of its logic. The [] is the starting value (an empty array) of the accumulator.
[]
Simplified, using the reduce function to produce a total based on an array of values, we could start the reduce loop with the value 0.
0
const arr = [1,2,3,4,5,6,7,8]; const newArr = arr.reduce((acc, cur) => acc + cur, 0) // 36
We could also start it with another value, perhaps as a running total.
More on reduce: developer.mozilla.org/en-US/docs/W...
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.
Don't forget
reduce
:)I was surprised this was not included :-)
Can't figure out, what does [], in itterable condition
The
reduce
function uses and accumulator as part of its logic. The[]
is the starting value (an empty array) of the accumulator.Simplified, using the reduce function to produce a total based on an array of values, we could start the reduce loop with the value
0
.We could also start it with another value, perhaps as a running total.
More on reduce: developer.mozilla.org/en-US/docs/W...