reduce() method removes duplicates from an array. The original code I found had ()s around the ternary operator like so
(arr.includes(item) ? arr : [...arr, item]) , but after removing them I found that it did not have an effect on the output. Is there a benefit to using them in this case?
let nums = [1, 2, 2, 3, 4, 5, 5] nums = nums.reduce((arr, item) => arr.includes(item) ? arr : [...arr, item], ); console.log(nums)