r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

Show parent comments

-4

u/CallMeOutWhenImPOS Mar 19 '19 edited Mar 19 '19

So basically removing the intersection of an array for the resulting unordered pair cartesian products? I wonder what the big O of such a function is.

1

u/kryptogalaxy Mar 19 '19

If the Set uses hashing, then it's O(n). It will iterate through the list and add each item to the set. Adding an item requires checking for uniqueness which can be O(1) assuming the underlying data structure is some kind of hash table. If it's not, then it would have to iterate through the current items. This would be O(n2).

-1

u/[deleted] Mar 19 '19

2

u/CallMeOutWhenImPOS Mar 19 '19

cartesian products are pretty simple shit, I'm dumb at this that's why I'm asking the question. Don't see why some of you have to be so negative

-1

u/[deleted] Mar 19 '19

I wasn't good at Maths in school so the first sentence sounded pretentious.

3

u/CallMeOutWhenImPOS Mar 19 '19

set theory is a lot more intuitive than calculus and geometry, and applies well into programming. Read up on it, I was never "good" at math, but in a programming sense this scope of math came easy