From b20b514bd41b4476e02843833cb7577859600f4a Mon Sep 17 00:00:00 2001 From: Colin Xie Date: Wed, 21 Jun 2017 12:19:27 -0700 Subject: [PATCH] solutions and test #15 --- solutions/15.js | 12 ++++++++++++ test/15.js | 23 +++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/solutions/15.js b/solutions/15.js index 981b075..5f1825f 100644 --- a/solutions/15.js +++ b/solutions/15.js @@ -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, }; diff --git a/test/15.js b/test/15.js index 26783f7..a962e3b 100644 --- a/test/15.js +++ b/test/15.js @@ -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); }); });