Skip to content

Commit

Permalink
Works. Uses match(), global flag on the regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
atom-box committed Dec 1, 2021
1 parent 79ad954 commit 1e6c88c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions countCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Return the number of times that the string "code" appears anywhere in the given string, except we'll accept any letter for the 'd', so "cope" and "cooe" count.

const countCode = (haystack) => {
const needle = /co.e/ig;
const successes = haystack.match(needle);
return successes.length;
};

console.log(countCode("aaacodebbb")); // 1
console.log(countCode("codexxcode")); // 2
console.log(countCode("cozexxcope")); // 2

// Next How to do this (in node?) Typescript

0 comments on commit 1e6c88c

Please sign in to comment.