Created
December 28, 2017 01:58
-
-
Save jlarocque/6887792de4250ea3584cf00bdb80a57d to your computer and use it in GitHub Desktop.
Prime
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
<script src='https://scottdalessandro.github.io/jasmine-total/js/jasmine-suite.min.js'></script> |
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
/* | |
Prime - Challenge: | |
The function `prime(num)` accepts a number argument and returns the boolean `true` if the number is a prime number otherwise it returns return `false`. | |
Examples: | |
- INPUT: prime(5); | |
- OUTPUT: true | |
- INPUT: prime(10); | |
- OUTPUT: false | |
*/ | |
// Write Code Below | |
function prime(num){ | |
for(i=2; i < num; i++){ | |
if (num%i === 0){ | |
return false; | |
} else { | |
return true; | |
} | |
} | |
} | |
describe('prime', function(){ | |
it('prime is a function', function(){ | |
expect(typeof prime).toEqual('function'); | |
}); | |
it('prime returns a boolean', function(){ | |
expect(typeof prime(10)).toEqual('boolean'); | |
}); | |
it('prime returns `true` if the number is prime', function(){ | |
expect(prime(5)).toEqual(true); | |
expect(prime(7)).toEqual(true); | |
}); | |
it('prime returns `false` if the number is not prime', function(){ | |
expect(prime(24)).toEqual(false); | |
expect(prime(56)).toEqual(false); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment