4 ms·
input.split('').filter((c) => c === chr).length; Edit: ah I assume you mean more like a histogram. Yeah, that's going to be less clean, e.g. input.split('').r
by ghayes 3y ago
input.split('').filter((c) => c === chr).length;
Edit: ah I assume you mean more like a histogram. Yeah, that's going to be less clean, e.g.
input.split('').reduce((acc, el) => ({...acc, [el]: ( acc[el] ?? 0 ) + 1 }), {});
- recursive 3y agoThis is exactly the type of code I'm talking about. That spread operator is producing a lot of garbage (in the GC sense) for no real reason. It's just to avoid mutation and a loop.