Message from JavaScript discussions

July 2017

— Lel

— 

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(hit, end));
return findNames(text, name, end, hits);
}

— Working version

— Still doesn't make much sense to actually store the same value to the array this many times though

— Why not just keep hits a number?

— And just + 1 everytime you get a hit?

— 

const findNames = (text, name, start = 0, hits = []) =>
(hit => hit === -1
? hits
: (end =>
(hits.push(text.substring(hit, end)),
findNames(text, name, end, hits))
)(hit + name.length)
)(text.indexOf(name, start));

Message permanent page

— Floofies What do you think about the readability of this?

— Exact same algorithm

— What does === mean ?

— Strict equal to

— Ok