I have 2 arrays:
var one = ['da22', 'ye66', '17hy']
and
var two = [{publicID: 'da22', score: '2'}, {publicID: '17hy', score: '2'}, {publicID: 'ye66', score: '2'}]
I want two
to be ordered by publicID
according to one
so it should be
two = [{publicID: 'da22', score: '2'}, {publicID: 'ye66', score: '2'}, {publicID: '17hy', score: '2'}]
Is there a built in method in NodeJS to do this?
I've got it working however its not very efficient. I have a method than can move an element from one index to another moveFromTo(oldIndex, newIndex
which I'm using with:
for (var r=0; r<one.length; r++) {
if (one[r] != two[r]['publicID']) {
two.moveFromTo(one.indexOf(two[r]['publicID']), r)
r=-1; continue;
}
}
But having to use that r=-1
as things move - although works - doesn't seem like the best of ideas.
Any ideas would be appreciated.
Many Thanks.