Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here's an example that made sense to me

elegant (readable / compact)

function isPalindrome(str) { return str == str.split('').reverse().join(''); }

efficient (~50x faster than above)

function isPalindrome(str) { var len = Math.floor(str.length / 2); for (var i = 0; i < len; i++) if (str[i] !== str[str.length - i - 1]) return false; return true; }

I would probably say elegance and efficiency are not aligned rather than at odds IMO because they may overlap or may not, they don't have the same goals.



Does just str.reverse() not work, by the way.


I didn't see that on MDN but would be cool. I get 'abc'.reverse() exception that it is not a function.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: