Skip to content

adding night 3 homework #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions isPrime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//Create a function to return true or false if a number passed in a prime number

var isPrime = function(num) {
var thisPrime = true;
for (i = 2; i <= Math.sqrt (num); i +=1) {
if (num % i === 0) {
thisPrime = false
}
}
return thisPrime;
}
console.log(isPrime(10));

10 changes: 10 additions & 0 deletions numSquaredMax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

var numSquared = function(maxNum) {
var perfSquared = [];
for (i = 0; (i*i) < maxNum ; i += 1) {
perfSquared.push(i*i);
}
return perfSquared;

}
console.log(numSquared(200));
25 changes: 25 additions & 0 deletions primesMax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//Using your isPrime() function, create a function primes that will return an array of all prime numbers up to a certain amount.

var isPrime = function(num) {
var thisPrime = true;
for (var i = 2; i <= Math.sqrt (num); i +=1) {
if (num % i === 0) {
thisPrime = false
}
}
return thisPrime;
};

var primes = function(maxPrime) {
var primeArr = [];
for (var i = 0; i < maxPrime; i += 1) {
if (isPrime(i) === true) {
primeArr.push(i);
}

}
return primeArr;

};
console.log(primes(45));

13 changes: 13 additions & 0 deletions sillySum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

var myArr = [1, 5, 10, 15, 7];

var sillySum = function(myArr) {
var count = 0;
for (i = 0; i < myArr.length; i += 1) {
count += (i * myArr[i]);
}
return count;
}

console.log(sillySum(myArr));