Skip to content

Commit

Permalink
solution and test for llipio#19
Browse files Browse the repository at this point in the history
  • Loading branch information
bettychow committed Jun 2, 2017
1 parent d17f752 commit 42d93ca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions solutions/19.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Betty Chow
// Find pais that sum to x

const solution = (arr, x) => {

let newArr= [];
for (let i = 0; i < arr.length; i++) {
for (let j=i+1; j < arr.length; j++ ) {
if (arr[i] + arr[j] === x) {
newArr.push([arr[i], arr[j]]);
}
}
}

return newArr;
};

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

describe('Pairs sum to x', () => {
it('should return pairs of number that sum to x', () => {
const result = solution([1,2,3,4,5], 6);
expect(result).eql([[1,5],[2,4]]);
});
it('should return pairs of number that sum to x', () => {
const result = solution([3,5], 8);
expect(result).eql([[3,5]]);
});
it('should return pairs of number that sum to x', () => {
const result = solution([4,2,9,3,8,6,7], 11);
expect(result).eql([[4,7],[2,9],[3,8]]);
});
});

0 comments on commit 42d93ca

Please sign in to comment.