mastodon.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
The original server operated by the Mastodon gGmbH non-profit

Administered by:

Server stats:

379K
active users

Raymond Camden

Smart JS folks - this is why I can't pass the Google hiring test:

Given 2 to 3 arrays (it will either be 2 or 3, it can change), how would you return an array that only contains items in ALL the arrays.

Every solution I have found only seems to work w/ an array of simple values. I have an array of objects with a primary key, id.

@raymondcamden Is that situation unchangeable? For example, could you use a Map instead to begin with?

Actually, I just assumed you wanted one of each object. Is that the case? If not, doesn’t the concat() method do what you need?

Again, lots I don’t know: is order important, etc.?

Will be easier to help if you show us some code :)

@aral imagine 2-3 arrays of objects. i need an array of items that appear in all of them. each object can be identified by a "id" property. if i used a Set i could get unique items from all 3, but thats not what i need, it has to be things that exist in all 3, or 2 (if it was just 2, it would be pretty simple)

@raymondcamden

Loop over number of arrays
For each item, output[item.id] = 1 if new else ++
Pool
Output all keys in output where value eq number of arrays

?

@raymondcamden when you get hired by Google I expect a kick back lol

@falken last time they called i said - happy to interview, no code test. they said, sorry, we have to do that, when can i schedule the call, i said, no thanks, bye.

That being said, I wouldn't mind ending up there in DevRel some day...

@raymondcamden can an id be in more than one array? If so, which object is the final value?

@myobie yea, imagine 2-3 searches against IndexedDB . @falken 's idea seems to be working for me - will share in a bit