Message from JavaScript discussions

July 2017

— How do u mean?

— 

"use strict";

function findNames(text, name, start = 0) {
const hits = [];
const hit = text.indexOf(name, start);
const end = hit + name.length;
if (hit !== -1) {
hits.push(text.substring(start, end));
findNames(text, name, end)
.forEach(result =>
hits.push(result));
}
return hits;
}

const text = "Valentine, Valentine, Valentine, Valentine, Valentine, Valentine.";

const myName = "Valentine";

console.log(findNames(text, myName));

— Logs:

[ 'Valentine',
', Valentine',
', Valentine',
', Valentine',
', Valentine',
', Valentine' ]

— Recursion ❤️

— Valentine

— Hrmm

— This could be optimized to be tail-recursive

— Wow nice thanks alot... You just OOP the entire code to still produce the same result😊☺

— ?

— OOP?

— I mean the use of your functions

— OOP Object oriented programming