-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
…ray of consecutively increasing numbers
test/18.js
Outdated
expect(result).to.equal(7); | ||
}); | ||
|
||
it('should return 94 for [89,90,91,92,93]', () => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
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.
…iption for test case two
@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 => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it!
CONGRATS! This is a great solution to issue #18 |
… consecutively increasing numbers