every with includes

Pangram
Pangram in JavaScript
export function isPangram(input) {
  const inputLowered = input.toLowerCase();
  return [...'abcdefghijklmnopqrstuvwxyz'].every((c) =>
    inputLowered.includes(c),
  );
}
  • This begins by lowercasing the input by using the String toLowerCase method.
  • It uses spread syntax to make an Array out of a string of the alphabet.
  • It then checks if all letters in the alphabet are contained in the input, using the Array method every with the String method includes.

If all letters of the alphabet are in the input, then the function returns true.

13th Nov 2024 · Found it useful?