Oliver Eyton-Williams f1c9b08cf3 fix(curriculum): add isHidden: false to challenges
This includes certificates (where it does nothing), but does not
include any translations.
2020-05-25 16:25:19 +05:30

1.6 KiB

id, title, isRequired, challengeType, isHidden, forumTopicId
id title isRequired challengeType isHidden forumTopicId
af7588ade1100bde429baf20 Missing letters true 5 false 16023

Description

Find the missing letter in the passed letter range and return it. If all letters are present in the range, return undefined.

Instructions

Tests

tests:
  - text: <code>fearNotLetter("abce")</code> should return "d".
    testString: assert.deepEqual(fearNotLetter('abce'), 'd');
  - text: <code>fearNotLetter("abcdefghjklmno")</code> should return "i".
    testString: assert.deepEqual(fearNotLetter('abcdefghjklmno'), 'i');
  - text: <code>fearNotLetter("stvwx")</code> should return "u".
    testString: assert.deepEqual(fearNotLetter('stvwx'), 'u');
  - text: <code>fearNotLetter("bcdf")</code> should return "e".
    testString: assert.deepEqual(fearNotLetter('bcdf'), 'e');
  - text: <code>fearNotLetter("abcdefghijklmnopqrstuvwxyz")</code> should return undefined.
    testString: assert.isUndefined(fearNotLetter('abcdefghijklmnopqrstuvwxyz'));

Challenge Seed

function fearNotLetter(str) {
  return str;
}

fearNotLetter("abce");

Solution

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;
}