DAY25:Detect Pangram


Posted by birdbirdmurmur on 2023-08-07

題目連結

https://www.codewars.com/kata/545cedaa9943f7fe7b000048

解法

function isPangram(string){
  const alphabet = 'abcdefghijklmnopqrstuvwxyz';
  const lowerString = string.toLowerCase();

  for (let char of alphabet) {
    if (lowerString.indexOf(char) === -1) {
      return false;
    }
  }
  return true;
}

筆記

使用for...ofalphabet一個一個拿出來比對
判斷是否存在 如果不存在就回傳false
跑完如果沒問題就回傳true

lowerString.indexOf(char) === -1
indexOfchar
=== -1相等於 沒找到(false)的意思


#javascript #Codewars #indexOf #for...of







Related Posts

部署 Node.js app 在 AWS EC2(Nginx + MySQL)

部署 Node.js app 在 AWS EC2(Nginx + MySQL)

為什麼「div」元素內只有一行文字,卻能直接寫上去?

為什麼「div」元素內只有一行文字,卻能直接寫上去?

Return the summation of the number smaller than n

Return the summation of the number smaller than n


Comments