Skip to content

Instantly share code, notes, and snippets.

@laser
Created August 3, 2012 04:14
Show Gist options
  • Save laser/3244265 to your computer and use it in GitHub Desktop.
Save laser/3244265 to your computer and use it in GitHub Desktop.
less than O(n+m)?
var all_items = [{
"name": "cat",
"id": 1
}, {
"name": "dog",
"id": 2
}, {
"name": "spoon",
"id": 3
}, {
"name": "ninja",
"id": 4
}];
var special_items_names = ["cat", "spoon"];
for (var n = 0, lenA = all_items.length; n < lenA; n++) {
for (var lenB = special_items_names.length, i = lenB-1; i >= 0; i--) {
if (all_items[n].name === special_items_names[i]) {
all_items[n].special = true;
special_items_names.pop();
break;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment