r/learnjavascript • • May 14 '21

Remove Duplicate Value from array

Post image
234 Upvotes

89 comments sorted by

View all comments

Show parent comments

78

u/StoneCypher May 14 '21

no, dramatically worse.

this is actually a terrible approach, and a big part of the reason why you shouldn't learn javascript from memes by dev.to spammers on reddit

16

u/[deleted] May 14 '21

It's less performant, but not dramatic. Whether or not this is faster is an implementation detail in the runtime essentially. It is a lot more concise though, and hard to get wrong. 99/100 times i'd just import uniq / uniqBy from lodash anyway.

-26

u/StoneCypher May 14 '21

It's less performant, but not dramatic.

It's the construction and iteration of an entirely unnecessary unordered container

It's not clear how you'd make this "dramatically worse" that this isn't, other than to just make it wrong, or do something nonsensical

Yes, it's dramatic. It's large constant big o lg n twice plus small constant big o n lg n for literally no reason.

.

Whether or not this is faster is an implementation detail in the runtime essentially

this isn't even close to correct

.

It is a lot more concise

Not than the good answer

.

99/100 times i'd just import uniq / uniqBy from lodash anyway.

Wow, please don't give advice anymore

I've had to update my libraries 11 times this week because people like you imported lodash or underscore for no good reason, and they're full of bugs and security problems

It's so hard to just have decent testing or doc generation because of things like this :(

This is the mindset that left a serious chunk of the internet broken over padLeft

4

u/[deleted] May 14 '21

This is the mindset that left a serious chunk of the internet broken over padLeft

This is also completely incorrect. People using packages was not the root cause of that problem. npm allowing packages to be removed at will was certainly a problem. people counting on npm to be always up was certainly a problem. javascript having a pathetic standard library was mainly to blame.

You weren't even right about a single thing in that massive wall of text which is pretty impressive.

1

u/StoneCypher May 14 '21

This is also completely incorrect. People using packages was not the root cause of that problem

It was literally 100% of the problem. It's a subtraction and a .repeat

 

npm allowing packages to be removed at will was certainly a problem.

This is required both by security common sense basics and by copyright law.

 

javascript having a pathetic standard library was mainly to blame.

It's not Javascript's fault that you don't know how to do this

By the way, Javascript does have this in the standard library directly, it's just called .padStart

Yes, that was already in Javascript before the package you're trying to make excuses for was added

Yes, they could have used a shim or a sham

 

You weren't even right about a single thing in that massive wall of text which is pretty impressive.

Sure thing, Jim

Sorry you don't like evidence or questions you can't answer

 

Can we see your mystery perf that you claimed to write? It's not getting the same results I did, and I'd like to see why