git » homepage.git » master » tree

[master] / archive / forums / hacker-news / raw / items / 3614613.json

{"by":"jfager","id":3614613,"kids":[3615192],"parent":3614550,"text":"You don't need a map, just a reduce (foldl, really).  Using underscore, no double calculation:<p><pre><code>    _.reduce(arr, function(p1, p2) {\n        var len = p2.firstName.length + p2.lastName.length;\n        return (len &#62; p1[1]) ? [p2, len] : p1;  \n    }, \n    [null, -1]);</code></pre>","time":1329784513,"type":"comment"}