Created
November 19, 2016 20:18
-
-
Save anonymous/3314a49cc40011d979bc03764fa60592 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/qupawe
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// display prime numbers up to n. | |
'use strict'; | |
var isPrime = function isPrime(number) { | |
if (number < 2) return false; | |
var sqrt = Math.floor(Math.sqrt(number)); | |
for (var i = 2; i <= sqrt; i++) { | |
if (number % i === 0) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
var getPrimeNumbersUpTo = function getPrimeNumbersUpTo(number) { | |
var primes = []; | |
var sqrt = Math.floor(Math.sqrt(number)); | |
for (var i = 0; i <= number; i++) { | |
if (isPrime(i)) { | |
primes.push(i); | |
} | |
} | |
return primes.join(', '); | |
}; | |
console.log(getPrimeNumbersUpTo(100)); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// display prime numbers up to n. | |
let isPrime = number => { | |
if (number < 2) return false; | |
let sqrt = (Math.floor(Math.sqrt(number))); | |
for (let i = 2; i <= sqrt; i++){ | |
if (number % i === 0) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
let getPrimeNumbersUpTo = number => { | |
var primes = []; | |
let sqrt = (Math.floor(Math.sqrt(number))); | |
for(let i=0; i <= number; i++){ | |
if(isPrime(i)){ | |
primes.push(i); | |
} | |
} | |
return primes.join(', '); | |
} | |
console.log(getPrimeNumbersUpTo(100));</script></body> | |
</html> |
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
// display prime numbers up to n. | |
'use strict'; | |
var isPrime = function isPrime(number) { | |
if (number < 2) return false; | |
var sqrt = Math.floor(Math.sqrt(number)); | |
for (var i = 2; i <= sqrt; i++) { | |
if (number % i === 0) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
var getPrimeNumbersUpTo = function getPrimeNumbersUpTo(number) { | |
var primes = []; | |
var sqrt = Math.floor(Math.sqrt(number)); | |
for (var i = 0; i <= number; i++) { | |
if (isPrime(i)) { | |
primes.push(i); | |
} | |
} | |
return primes.join(', '); | |
}; | |
console.log(getPrimeNumbersUpTo(100)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment