Skip to content

Instantly share code, notes, and snippets.

@tmodrzynski
Created November 26, 2015 21:05
Show Gist options
  • Save tmodrzynski/1ffcb9e705a6a4a79eaf to your computer and use it in GitHub Desktop.
Save tmodrzynski/1ffcb9e705a6a4a79eaf to your computer and use it in GitHub Desktop.
RMS 4727
var _ = require('underscore')
// function sayHello() {
// console.log('Hello, World');
// }
// _.times(5, sayHello);
function test(i) {
var arr = [];
var n = 1;
for (n; n <= i; n++) {
if (n % 3 == 0 && n % 5 == 0) {
arr.push('fizzbuzz');
} else if (n % 3 ==0) {
arr.push('fizz');
} else if (n % 5 == 0) {
arr.push('buzz');
} else {
arr.push(n.toString());
}
}
return arr;
}
console.log(test(100));
var _ = require('underscore')
// function sayHello() {
// console.log('Hello, World');
// }
// _.times(5, sayHello);
function add(val1) {
return function temp(val2) {
return val1 + val2;
};
}
// console.log(add(sample)); // should log 2
var x = add(2);
// ...
console.log(x(5)); // should log 7
function showPrimeList() {
$scope.list = [];
var arr = [];
var test = test(100);
for (var i = 1; i <= test.length; i++) {
if(checkPrime(i)) {
$scope.list[i] = 'yes';
} else {
$scope.list[i] = 'no';
}
}
}
function test(i) {
var arr = [];
var n = 1;
for (n; n <= i; n++) {
if (n % 3 == 0 && n % 5 == 0) {
arr.push('fizzbuzz');
} else if (n % 3 ==0) {
arr.push('fizz');
} else if (n % 5 == 0) {
arr.push('buzz');
} else {
arr.push(n.toString());
}
}
return arr;
}
function checkPrime(n) {
if (isNaN(n) || !isFinite(n) || n % 1 || n < 2) {
return false;
}
if (n % 2 === 0) {
return (n == 2);
}
var m = Math.sqrt(n);
for (var i=3; i<=m; i+=2) {
if (n % i === 0) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment