July 2017
— Yeah, this is not OOP
function findNames(text, name, start = 0, hits = []) { const hit = text.indexOf(name, start); if (hit === -1) { return hits; } const end = hit + name.length; hits.push(text.substring(start, end)); return findNames(text, name, end, hits);}
— This is tailcall-optimized
— Yeah, this is NOT OOP though
— So this is more efficient
— And will work for strings of any size
— Using the --harmony-tailcalls flag at least
--harmony-tailcalls
— There's a theorem that any recursive function can be rewritten as a tailrecursive function
— ???
— U can only see it.
— Magic 🌚😂
— Jk