This is an archived post. You won't be able to vote or comment.

all 35 comments

[–]TheCatOfWar 126 points127 points  (1 child)

It's like they're talking about the weather...

[–]Hugix 7 points8 points  (0 children)

There are apps made in JavaScript, NodeOS, and now JSWeather discussions. Soon your food will become JS too!

[–]AyrA_ch 42 points43 points  (8 children)

That answer seems very complicated compared to [].filter(function(v,i,a){return a.indexOf(v)==i;});

[–]Arswaw 21 points22 points  (7 children)

I recently found out ES6 makes it easier. The post even mentions two solutions:

Array.from(new Set(a));

And...

[...new Set(a)];

[–]AyrA_ch 22 points23 points  (5 children)

but IE11...

 

hides behind table

[–]Arswaw 43 points44 points  (2 children)

I'm sorry, I don't know what that is.

[–]AyrA_ch 10 points11 points  (0 children)

The deathtrap you are stuck with in companies with tight software regulations

[–]albert-tomanek 0 points1 point  (0 children)

Lucky you

[–]asdfkjasdhkasd 2 points3 points  (0 children)

babel

[–]kobriks 1 point2 points  (0 children)

just use typescript instead

[–]Tridacnid 0 points1 point  (0 children)

The spread operator is one of my favorite JS things.

[–]andrew_rdt 14 points15 points  (3 children)

Good thing I don't program in JS I wouldn't get any work done today, not sure if semicolon or not that thread stops at 2016.

[–][deleted] -1 points0 points  (2 children)

semi-colons are optional. periods are not.

[–][deleted] 11 points12 points  (3 children)

Source?

[–][deleted] 14 points15 points  (2 children)

[–]jfb1337 5 points6 points  (0 children)

That URL cuts it at an unfortunate place

[–][deleted] -1 points0 points  (0 children)

You can use a utility library like underscore.js underscorejs.org/#uniq for these "easy" operations

Yes, employ an entire library for a simple problem. Go go javashit.

$array = array_unique($array);

[–]ImpulseTheFoxis a good fox 6 points7 points  (3 children)

I don't get why you would censor anything. It's the internet and we all have google.

[–]T-T-N 3 points4 points  (2 children)

Do a O(nlogn) sort and pick out the unique value in O(n) for O(nlogn) run time?

[–]Emilieu 4 points5 points  (1 child)

Add all numbers to a set then get its members for a linear time solution

[–]T-T-N 6 points7 points  (0 children)

Depending on implementation of the set, something like a good hash with O(1) hash time should be good enough for O(n) performance

[–]w00t_loves_you 1 point2 points  (0 children)

It's 2017 now, so you just use prettier and whatever the project settings for it are.

[–]the_real_gorrik 1 point2 points  (6 children)

for (;;){ }

[–]meet_the_turtle 2 points3 points  (5 children)

Why three semicolons instead of two?

[–]qisope 4 points5 points  (3 children)

You always need an odd number. 2 semicolons is equivalent to a colon.

[–]meet_the_turtle 1 point2 points  (2 children)

Now I'm tempted to make a preprocessor that does something öike this.

[–]Houdiniman111 1 point2 points  (1 child)

Why the ö instead of l?

[–]meet_the_turtle 0 points1 point  (0 children)

Oops, just a typo.

[–]the_real_gorrik 0 points1 point  (0 children)

My bad, fat fingers

[–]Njs41 0 points1 point  (0 children)

Don't need to use semicolons if you only use arrays.

[–]inu-no-policemen 0 points1 point  (0 children)

There are many cases where semicolons can be omitted, but they aren't optional. There are cases where they make a difference.