Created
August 22, 2010 08:13
-
-
Save chaitanyagupta/543519 to your computer and use it in GitHub Desktop.
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 findItem = function(jid, items){ | |
for(var i = 0; i < items.length; ++i){ | |
var item = items[i]; | |
if(item.jid === jid){ | |
return item; | |
} | |
} | |
return null; | |
} |
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 findItem = function(jid, items){ | |
var foundItem = null; | |
dojo.some(items, function(item){ | |
return (item.jid === jid) ? (foundItem = item, true) : false; | |
}); | |
return foundItem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oh, yeah some is pretty neat in that it returns the value. I like that. Ruby's array.find does this, that's why I called it find. There is also an "any" which is meant to be used like some. Except you can rely on it even if your array contains false or nil ;-)