What do ()s do here?

This 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)

There is no benefit as far as correctness or performance is concerned. Perhaps someone thought that they made the code a little cleaner or easier to read since it using the ternary operator?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.