Created
August 3, 2012 04:14
-
-
Save laser/3244265 to your computer and use it in GitHub Desktop.
less than O(n+m)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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