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

JS solution and tests for Issue #18 - Find missing number in array of… #54

Merged
merged 3 commits into from
May 31, 2017

Conversation

zachnagatani
Copy link
Contributor

… consecutively increasing numbers

test/18.js Outdated
expect(result).to.equal(7);
});

it('should return 94 for [89,90,91,92,93]', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

description incomplete. [...91, 92, 93, 95]

solutions/18.js Outdated
let missingNum = null,
i = 0;

while (!missingNum && i < arr.length - 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

food for thought. Since there is only 1 missing number, and your goal is to return that number, you might not even need the missingNum variable. start i = 1.

while (i < arr.length -1 && arr[i-1] +1 === arr[i] )....

You don't have to make this change, just food for thought. Good job!

test/18.js Outdated
const result = solution([1,2,3,4,5]);
expect(result).to.equal(null);
});
});
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 add a test case for negative numbers please? thx.

@zachnagatani
Copy link
Contributor Author

@songz Thanks for the feedback! I liked your approach to the solution, so I just added it as an alternative one in the bottom of the file. Had to make one change to the while condition so that I could also return null if no missing number is found.

solutions/18.js Outdated
* @param {Number[]} arr - An array of consecutively increasing numbers
* @returns {Number|null} missingNum - the number missing from the input array or null if none is found
*/
// const solution = arr => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of commenting out previous solution, could you rename them? solution, solution1, and export all the solutions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

@songz
Copy link
Collaborator

songz commented May 31, 2017

CONGRATS! This is a great solution to issue #18

@songz songz merged commit cc60d0d into llipio:master May 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants