Skip to content

Instantly share code, notes, and snippets.

@xk xk/happyNumbers.js

Created Feb 10, 2014
What would you like to do?
Concise Happy Numbers JavaScript
//2014-02-10 concise happy numbers JavaScript
function happy (n) {
var past= [];
while (n= [], function (a,n) { return a+n*n }, 0))
if (n === 1) return 1; else if (past.indexOf(n) >= 0) return 0; else past.push(n);
for (var i=0 ; i<=100 ; ++i) happy(i) && console.log(i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.