2.1 KiB
2.1 KiB
id, title, isRequired, challengeType
id | title | isRequired | challengeType |
---|---|---|---|
af7588ade1100bde429baf20 | Missing letters | true | 5 |
Description
Instructions
Tests
tests:
- text: <code>fearNotLetter("abce")</code> should return "d".
testString: 'assert.deepEqual(fearNotLetter(''abce''), ''d'', ''<code>fearNotLetter("abce")</code> should return "d".'');'
- text: <code>fearNotLetter("abcdefghjklmno")</code> should return "i".
testString: 'assert.deepEqual(fearNotLetter(''abcdefghjklmno''), ''i'', ''<code>fearNotLetter("abcdefghjklmno")</code> should return "i".'');'
- text: <code>fearNotLetter("stvwx")</code> should return "u".
testString: 'assert.deepEqual(fearNotLetter(''stvwx''), ''u'', ''<code>fearNotLetter("stvwx")</code> should return "u".'');'
- text: <code>fearNotLetter("bcdf")</code> should return "e".
testString: 'assert.deepEqual(fearNotLetter(''bcdf''), ''e'', ''<code>fearNotLetter("bcdf")</code> should return "e".'');'
- text: <code>fearNotLetter("abcdefghijklmnopqrstuvwxyz")</code> should return undefined.
testString: 'assert.isUndefined(fearNotLetter(''abcdefghijklmnopqrstuvwxyz''), ''<code>fearNotLetter("abcdefghijklmnopqrstuvwxyz")</code> should return undefined.'');'
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;
}