Better HN
topnewbestaskshowjobs
Log inSign up

tcqag

1 karma · joined Jan 20, 2015 (11y ago) · 2 submissions

Submissions

comment 11y ago · link · parent

Just fyi indexOf is O(n), which means if you tried to do:

  var count = 1000000;
  var arr = foo(count);
  for (var i = 0; i < count; i++)
    arr[i]();
It will take O(n^2) and will probably never complete whereas all the other solutions here will probably take ~1second.

comment 11y ago · link · parent

Here's a solution using closure: http://codepen.io/anon/pen/KwmQam