Skip to content

Instantly share code, notes, and snippets.

@birkir
Created December 11, 2014 17:48
Show Gist options
  • Save birkir/65bcc93a01cef5dd8217 to your computer and use it in GitHub Desktop.
Save birkir/65bcc93a01cef5dd8217 to your computer and use it in GitHub Desktop.
Jóladagatal 11/24 - Umturnun á stafrófi
// get factorial by iteration (faster than recursive)
Math.factorial = function (n) {
var a = 1;
for (var i = 2; i < n; i++) {
a *= i;
}
return a;
}
// setup test case
var alphabet = 'AÁBDÐEÉFGHIÍJKLMNOÓPRSTUÚVXYÝÞÆÖ';
var target = 'JÓL';
// calculate answer
Math.factorial(alphabet.length - target.length + 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment