首页 > 解决方案 > 元音没有被过滤掉

问题描述

只是学习 JavaScript 的基础知识并尝试从字符串中去掉元音:

function disemvowel(str) {
  let no_vowels = '';
  for (let a = 0; a < str.length; a++) {
    if (str[a] !== 'a' || str[a] !== 'A' || str[a] !== 'i' ||
        str[a] !== 'I' || str[a] !== 'o' || str[a] !== 'O' ||
        str[a] !== 'u' || str[a] !== 'U' || str[a] !== 'e' ||
                                              str[a] !== 'E') {
      // if none of the above is in the index add it to no_vowels
      no_vowels += str[a];
   }
  }
  return no_vowels;
}

字符串不变。为什么 ?

标签: javascript

解决方案


推荐阅读