loading...

re: Daily Coding Problem #1 VIEW POST

TOP OF THREAD FULL DISCUSSION
re: ATM I see 2 proposals for JS, here's another one taking advantage of the fact that JS arrays are sparse: function twoNumbersEqual(inList, k) { co...
 

there was actually an article recently that touched on the subject mentioned by Serhii Sakal dev.to/_codingblocks/when-is-an-ar...
I was wondering, why not just use an object instead of an array?
let's take a simple example, where you have something like this

const a = [1, 2];
a[1000] = 1000;

console.log(a);

and look at the size of a.
even with your example, the created lookup array is bigger than the given array, so you're using more memory than needed.

Code of Conduct Report abuse