Skip to content

Commit

Permalink
llipio#18 solutions and test
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinX13 committed Jun 5, 2017
1 parent cc60d0d commit 828955a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
21 changes: 21 additions & 0 deletions test/yourTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const expect = require('chai').expect;
let solution = require('../yourSolution').solution;
//solution = require('./yourSolution').solution;

describe('missing number', () => {
it('the missing number is 7', () => {
expect(solution([5,6,8,9])).eql(7);
});
it('there is no missing number', () => {
expect(solution([7,8,9])).eql(null);
});
it('the missing number is 100', () => {
expect(solution([99,101,102,103])).eql(100);
});
it('the missing number is 1023', () => {
expect(solution([1020,1021,1022,1024])).eql(1023);
});
it('the missing number is -21', () => {
expect(solution([-24,-23,-22,-20,-19])).eql(-21)
});
});
20 changes: 17 additions & 3 deletions yourSolution.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// Name
// Problem Description
// Takes in an array and finds the missing consecutive number

const solution = () => {
// input: [5,6,8,9]
// output: 7

/**
* @param {number[]} arr - an array of consecutive numbers inputted
* @return {number} missingNum - the missing number or null if the array has no missing number
*/

const solution = (arr) => {
let missingNum = null;
for(let i = 0; i < arr.length - 1; i++){
if(arr[i] + 1 !== arr[i + 1]){
missingNum = arr[i] + 1;
}
}
return missingNum;
};

module.exports = {
Expand Down

0 comments on commit 828955a

Please sign in to comment.