Skip to content

Commit

Permalink
solved #15: check a character in a string
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophia committed Oct 29, 2017
1 parent 44fa977 commit 9a7a406
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions solutions/15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const strHas = (string, c, i=0) => {
if (i > string.length-1) return false;
if (string[i] === c) return true;
return strHas(string, c, i+1);
};
module.exports = strHas;

11 changes: 11 additions & 0 deletions test/15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const strHas = require('../solutions/15.js');
const test = (string, c, result) => {
if (strHas(string, c) === result) {
console.log("Code is correct!");
} else {
console.log("Check code again");
};
};
test("hello", "e", true); //true===true, code is correct
test("hello", "a", false); //false===false, code is correct
test("hello", "a", true); //false != true, check again

0 comments on commit 9a7a406

Please sign in to comment.