Last active
March 11, 2016 19:30
-
-
Save vicneanschi/4ceed82f619042c96fed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function primes(num){ | |
var result = [2, 3]; | |
for(var i = 5; i<= num; i+=2){ | |
if ( result.every( x => i % x ) ) { | |
result.push(i); | |
} | |
} | |
return result; | |
} | |
function gcdArr(arr){ | |
return arr.reduce((prev, curr) => gcd(prev, curr)); | |
} | |
function gcd(a, b) { | |
var t; | |
while (b !== 0) { | |
t = b; | |
b = a % b; | |
a = t; | |
} | |
return a; | |
} | |
function lcm(a, b){ | |
return a * b / gcd(a, b); | |
} | |
function getRotations(x){ | |
var result = []; | |
x = x.toString().split(''); | |
for(var i=0; i< x.length-1; i++){ | |
// rotate | |
x.unshift(x.pop()); | |
result.push(x.join('')); | |
} | |
return result; | |
} | |
function formatNumber(x){ | |
// Matches a zero-width non-word boundary, such as between two letters or between two spaces. | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp | |
//return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
return x.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment