Created
May 28, 2015 02:57
-
-
Save ChanChar/b7bbacaf358471a60a14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// write myMap(array, callback) | |
Assessment.myMap = function(array, callback) { | |
var mappedArr = []; | |
for (n=0; n < array.length; n++) { | |
mappedArr.push(callback(array[n])); | |
} | |
return mappedArr; | |
}; | |
// write primes(n) | |
Assessment.primes = function(n) { | |
function isPrime(num) { | |
var prime = true; | |
if (num === 2) { | |
return true; | |
} else { | |
for (f = 2; f < num; f++) { | |
if (num % f === 0) { | |
prime = false; | |
} | |
} | |
} | |
return prime; | |
} | |
var primes = []; | |
var currentNum = 2; | |
while (primes.length < n) { | |
if (isPrime(currentNum)) { | |
primes.push(currentNum); | |
} | |
currentNum++; | |
} | |
return primes; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment