1

Return true if none of the letters in the blacklist are present in the phrase. If at least one letter from blacklist is present in the phrase return false;

Comparison should be case insensitive. Meaning 'A' == 'a'.

Не могу понять что не так , надеюсь на вашу помощь❤

function hasNoneLetters(blacklist, phrase) {
  // write code here
  let p = phrase.toLowerCase();
  let b = blacklist.toLowerCase();
  let count = 0;
 for(let i = 0; i < b.length; i++){
   if(p.indexOf(b[i]) != -1){
     count += 1;
   }
 }
 if(count === b.length){
   return true;
 }
 return false;
}

2 ответа 2

4

function hasNoneLetters(blacklist, phrase) {
  let p = phrase.toLowerCase();
  let b = blacklist.toLowerCase();
  for (let i = 0; i < b.length; i++) {
    if (p.indexOf(b[i]) != -1) {
      return false;
    }
  }
  return true;
}

console.log(hasNoneLetters('ZqG', 'The Walrus And The Carpenter'));
console.log(hasNoneLetters('ZwG', 'The Walrus And The Carpenter'));

1
0

String.prototype.hasForbiddenCharacters = function(forbiddenCharacters, caseSensitive = false) {
  const text = caseSensitive ? this : this.toLowerCase();
  const characters = caseSensitive ? forbiddenCharacters : forbiddenCharacters.toLowerCase();
  return !!characters.split('').find(character => text.indexOf(character) !== -1);
}

// Регистронезависимый поиск
console.log('The Walrus And The Carpenter'.hasForbiddenCharacters('w'));
// -> true

// Регистрозависимый поиск
console.log('The Walrus And The Carpenter'.hasForbiddenCharacters('w', true));
// -> false

console.log('The Walrus And The Carpenter'.hasForbiddenCharacters('ZwG'));
// -> true

console.log('The Walrus And The Carpenter'.hasForbiddenCharacters('ZqG'));
// -> false

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.