JavaScript中的双辅音

I made a function double consonant(). Here it's all well. But when I try to change little the logic with symbol !== in second function double_consonant_2() my program work wrong and i'm confused.

i want to say that each element from sentence which is not equal with vowel. i mean equal with consonant. Double the words and between them add the letter o.

// double consonant with consonant variable.
function double_consonant(sentence) {
  var result = "";
  var consonant = "qwrtypsdfghjklzxcvbnm";
  for (var i = 0; i < sentence.length; i++) {
    for (var j = 0; j < consonant.length; j++) {
      if (sentence[i] === consonant[j]) {
        result += sentence[i] + "o" + sentence[i];
      }
    }
  }

  return result;
}

console.log(double_consonant("good"));


// dobule consonant with vowel variable.
function dobule_consonant_2(sentence) {
  var result = "";
  var vowel = "aeouiAEOUI";
  for (var i = 0; i < sentence.length; i++) {
    for (var j = 0; j < vowel.length; j++) {
      if (sentence[i] !== vowel[j]) {
        result += sentence[i] + "o" + sentence[i];
      }
    }
  }

  return result;
}

console.log(dobule_consonant_2("here"));
评论