Skip to content

Commit

Permalink
solutions and test llipio#15
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinX13 committed Jun 21, 2017
1 parent 4b177b3 commit b20b514
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 12 additions & 0 deletions solutions/15.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ const solution = (fullString, subString) => {
return fullString.includes(subString);
};

// Colin Xie
const solution1 = (fullString, subString) => {
for(let i = 0; i < fullString.length; i++){
let subFull = fullString.substring(i,i + subString.length);
if(subFull === subString){
return true;
}
}
return false;
};

module.exports = {
solution,
solution1,
};
23 changes: 21 additions & 2 deletions test/15.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
const expect = require('chai').expect;
let solution = require('../solutions/15').solution;
let solution1 = require('../solutions/15').solution1;
// solution = require('../yourSolution').solution;

describe('is substring', () => {
it('should return true if second input is a substring of first input', () => {
const result = solution('all your base are belong to us', 'ase ar');
let result = solution('all your base are belong to us', 'ase ar');
expect(result).to.equal(true);
result = solution1('all your base are belong to us', 'ase ar');
expect(result).to.equal(true);
});

it('should return false is second input is NOT a substring of first input',
() => {
const result = solution('i love tacos more than you', 'carne asada');
let result = solution('i love tacos more than you', 'carne asada');
expect(result).to.equal(false);
result = solution1('i love tacos more than you', 'carne asada');
expect(result).to.equal(false);
});

it('should return true if second input is a substring of the first input', () => {
let result = solution('ab cd ef g', 'ef');
expect(result).to.equal(true);
result = solution1('ab cd ef g', 'ef');
expect(result).to.equal(true);
});

it('should return false if second input is NOT a substring of first input', () => {
let result = solution('can', 'cn');
expect(result).to.equal(false);
result = solution1('can', 'cn');
expect(result).to.equal(false);
});
});

0 comments on commit b20b514

Please sign in to comment.