Created
June 5, 2014 09:05
-
-
Save teebot/e20ad1a824a25ebc4738 to your computer and use it in GitHub Desktop.
any object by its id from a collection
This file contains 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
employees = [{ id : 1, name : "tib" }, { id : 2, name : "dude" }] | |
search = (input, id) -> | |
for i in [0..input.length - 1] | |
if (input[i].id == id) | |
return input[i]; | |
return null | |
console.log search(employees, 2).name | |
# as angular filter | |
# return any object by its id from a collection | |
app.filter 'getById', -> | |
return (input, id) -> | |
for i in [0..input.length - 1] | |
if (input[i].id == id) | |
return input[i]; | |
return null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment