Skip to content
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

Test & solution for #59 (MERGE CONFLICTS RESOLVED) #105

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
16 changes: 16 additions & 0 deletions solutions/59.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// output: false

// Solution by Colin Xie @ColinX13
// Solution1 by Maricris Bonzo @Seemcat

/**
* Returns true or false based on whether the number is prime or not prime
* @param {number} num - a number that is being input
Expand All @@ -19,6 +21,20 @@ const solution = (num) => {
}
return true;
};

const solution1 = (num) => {
if(num === 1 || num === 0 || num === -1){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rewrite this condition so that it can handle num like -2? or -3452?

return false;
}
for(let i = 2; i < Math.sqrt(num); i++){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using a specific algorithm that may not be known to general audience, it is good practice to leave a comment explaining the algorithm. In this case, the comment can say Trial division test for Primality: divide from 2 to the square root of the number

if(num%i === 0){
return false;
}
}
return true;
};

module.exports = {
solution,
solution1
};
17 changes: 17 additions & 0 deletions test/59.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const expect = require('chai').expect;
let solution = require('../solutions/59').solution;
let solution1 = require('../solutions/59').solution1;
// solution = require('./yourSolution').solution;

describe('prime numbers', () => {
Expand All @@ -18,5 +19,21 @@ describe('prime numbers', () => {
it('15 should not be a prime number', () => {
expect(solution(15)).eql(false);
});
it('1 should not be a prime number', () => {
expect(solution1(1)).eql(false);
});
it('13 is a prime number', () => {
expect(solution1(13)).eql(true);
});
it('-1 should not be a prime number', () => {
expect(solution1(-1)).eql(false);
});
it('0 should not be a prime number', () => {
expect(solution1(0)).eql(false);
});
it('15 should not be a prime number', () => {
expect(solution1(15)).eql(false);
});

});