freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../intermediate-algorithm-scri.../missing-letters.md

1.3 KiB

id title challengeType forumTopicId dashedName
af7588ade1100bde429baf20 Encontrar as letras faltando 5 16023 missing-letters

--description--

Encontre a letra que falta no intervalo de letras passado e devolva-a.

Se todas as letras estiverem presentes no intervalo, retorne undefined.

--hints--

fearNotLetter("abce") deve retornar a string d.

assert.deepEqual(fearNotLetter('abce'), 'd');

fearNotLetter("abcdefghjklmno") deve retornar a string i.

assert.deepEqual(fearNotLetter('abcdefghjklmno'), 'i');

fearNotLetter("stvwx") deve retornar a string u.

assert.deepEqual(fearNotLetter('stvwx'), 'u');

fearNotLetter("bcdf") deve retornar a string e.

assert.deepEqual(fearNotLetter('bcdf'), 'e');

fearNotLetter("abcdefghijklmnopqrstuvwxyz") deve retornar undefined.

assert.isUndefined(fearNotLetter('abcdefghijklmnopqrstuvwxyz'));

--seed--

--seed-contents--

function fearNotLetter(str) {
  return str;
}

fearNotLetter("abce");

--solutions--

function fearNotLetter (str) {
  for (var i = str.charCodeAt(0); i <= str.charCodeAt(str.length - 1); i++) {
    var letter = String.fromCharCode(i);
    if (str.indexOf(letter) === -1) {
      return letter;
    }
  }

  return undefined;
}