Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});