MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/nc6i5j/remove_duplicate_value_from_array/gy71so0/?context=9999
r/learnjavascript • u/suprabha-supi • May 14 '21
89 comments sorted by
View all comments
20
Does this perform better than filter()?
2 u/47milliondollars May 14 '21 Would filter even work? Or do you have to use reduce to check if the value exists yet in an accumulator? 7 u/space_scarab May 14 '21 arr.filter((el, index) => { return arr.indexOf(el) === index; }); 10 u/[deleted] May 14 '21 edited May 14 '21 arr.filter((el, index) => arr.indexOf(el) === index);Works too!(but worth saying that shorthand isn't always the most readable and shouldn't be your default approach!) 2 u/StoneCypher May 14 '21 is there any difference there other than switching to an arrow? 0 u/[deleted] May 14 '21 [deleted] 1 u/grooomps May 15 '21 So a function without a fat arrow doesn't have explicit return?
2
Would filter even work? Or do you have to use reduce to check if the value exists yet in an accumulator?
7 u/space_scarab May 14 '21 arr.filter((el, index) => { return arr.indexOf(el) === index; }); 10 u/[deleted] May 14 '21 edited May 14 '21 arr.filter((el, index) => arr.indexOf(el) === index);Works too!(but worth saying that shorthand isn't always the most readable and shouldn't be your default approach!) 2 u/StoneCypher May 14 '21 is there any difference there other than switching to an arrow? 0 u/[deleted] May 14 '21 [deleted] 1 u/grooomps May 15 '21 So a function without a fat arrow doesn't have explicit return?
7
arr.filter((el, index) => { return arr.indexOf(el) === index; });
10 u/[deleted] May 14 '21 edited May 14 '21 arr.filter((el, index) => arr.indexOf(el) === index);Works too!(but worth saying that shorthand isn't always the most readable and shouldn't be your default approach!) 2 u/StoneCypher May 14 '21 is there any difference there other than switching to an arrow? 0 u/[deleted] May 14 '21 [deleted] 1 u/grooomps May 15 '21 So a function without a fat arrow doesn't have explicit return?
10
arr.filter((el, index) => arr.indexOf(el) === index);
Works too!
(but worth saying that shorthand isn't always the most readable and shouldn't be your default approach!)
2 u/StoneCypher May 14 '21 is there any difference there other than switching to an arrow? 0 u/[deleted] May 14 '21 [deleted] 1 u/grooomps May 15 '21 So a function without a fat arrow doesn't have explicit return?
is there any difference there other than switching to an arrow?
0 u/[deleted] May 14 '21 [deleted] 1 u/grooomps May 15 '21 So a function without a fat arrow doesn't have explicit return?
0
[deleted]
1 u/grooomps May 15 '21 So a function without a fat arrow doesn't have explicit return?
1
So a function without a fat arrow doesn't have explicit return?
20
u/slowthedataleak May 14 '21
Does this perform better than filter()?