Skip to content

Instantly share code, notes, and snippets.

Created November 19, 2016 20:18
Show Gist options
  • Save anonymous/3314a49cc40011d979bc03764fa60592 to your computer and use it in GitHub Desktop.
Save anonymous/3314a49cc40011d979bc03764fa60592 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/qupawe
<!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>
// 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