DEV Community

Discussion on: Daily Challenge #244 - Search for Letters

Collapse
 
mattymaloney profile image
mattymaloney • Edited
const countEm = (str) => {
  str = str.toLowerCase();
  return 'abcdefghijklmnopqrstuvwxyz'.split('').map((letter) => {
    return str.indexOf(letter) === -1 ? '0' : '1';
  }).join('')
};

Thanks for the challenge!

Collapse
 
qm3ster profile image
Mihail Malo

There's also String.prototype.includes

const letters = "abcdefghijklmnopqrstuvwxyz".split("")
const countEm = str => {
  str = str.toLowerCase()
  return letters.map(letter => str.includes(letter) ? "0" : "1").join("")
}