On Fri, Mar 9, 2012 at 10:36 AM, Roly Fentanes <[email protected]> wrote:
> btw http://www.devthought.com/2011/12/22/a-string-is-not-an-error/ +1 for that, and while we are at it: The whole thread is a great example why it is so important to use libraries like underscore's find: http://documentcloud.github.com/underscore/#find even for seemingly trivial tasks. And getUsers is probably a better name than the rubyfied one. > > On Friday, March 9, 2012 3:30:49 AM UTC-7, Angelo Chen wrote: >> >> Hi, >> >> Struggling to change coding practice, following has two samples, which >> one is correct? or any other approaches available? >> >> exports.get_user = function (id, func) { >> var found = false >> for (var i = 0; i < users.length; i ++) { >> if (users[i].id === id) { >> found = true >> func(**null, users[i]) >> break; >> } >> } >> if (!found) >> func("**NOT_FOUND", null) >> } >> >> >> exports.get_user = function (id, func) { >> for (var i = 0; i < users.length; i ++) { >> if (users[i].id === id) { >> func(**null, users[i]) >> break; >> } >> if (i == users.length) >> func("**NOT_FOUND", null) >> } >> } > > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
