javascript - Algorithm for returning common items in multiple arrays -
this question has reply here:
simplest code array intersection in javascript 20 answerswhat efficient way homecoming mutual elements between multiple big arrays? arrays contain strings, knowing how generically nice too.
for example, input of ['a', 'b'], ['a', 'b', 'c'], ['b', 'c'] should homecoming ['b'].
it depends on comparing... if it's alphabet letters create arrays have 26 slots (1 each alphabet letter) , give them values of 0 (that letter not in list) or 1 (the letter in list)... compile (add) matrices together, let's have 5 arrays... slots value 5 mean slot had 1 in 5 arrays, therefor letter showed in 5 arrays.
javascript algorithm
No comments:
Post a Comment