Skip to content

Instantly share code, notes, and snippets.

@giannispan
Created February 1, 2016 17:14
Show Gist options
  • Save giannispan/57dc99873ed4eb78d874 to your computer and use it in GitHub Desktop.
Save giannispan/57dc99873ed4eb78d874 to your computer and use it in GitHub Desktop.
Triangle number check
function isTriangleNumber(number) {
if (isNaN(number) || number != parseInt(number, 10)) return false;
else if (number == 0 || number == 1) return true;
else
var m = (Math.sqrt(8*number+1) - 1) / 2;
if (m != parseInt(m,10)) return false;
else return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment