Skip to content

Instantly share code, notes, and snippets.

@jlarocque
Created December 28, 2017 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlarocque/6887792de4250ea3584cf00bdb80a57d to your computer and use it in GitHub Desktop.
Save jlarocque/6887792de4250ea3584cf00bdb80a57d to your computer and use it in GitHub Desktop.
Prime
<script src='https://scottdalessandro.github.io/jasmine-total/js/jasmine-suite.min.js'></script>
/*
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