1.8 KiB
1.8 KiB
id, challengeType, localeTitle
id | challengeType | localeTitle |
---|---|---|
af7588ade1100bde429baf20 | 5 | 丢失的字母 |
Description
undefined
。
如果你遇到了问题,请点击帮助。
Instructions
Tests
tests:
- text: "<code>fearNotLetter('abce')</code>应该返回 'd'。"
testString: assert.deepEqual(fearNotLetter('abce'), 'd');
- text: "<code>fearNotLetter('abcdefghjklmno')</code>应该返回 'i'。"
testString: assert.deepEqual(fearNotLetter('abcdefghjklmno'), 'i');
- text: "<code>fearNotLetter('stvwx')</code>应该返回 'u'。"
testString: assert.deepEqual(fearNotLetter('stvwx'), 'u');
- text: "<code>fearNotLetter('bcdf')</code>应该返回 'e'。"
testString: assert.deepEqual(fearNotLetter('bcdf'), 'e');
- text: "<code>fearNotLetter('abcdefghijklmnopqrstuvwxyz')</code>应该返回<code>undefined</code>。"
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;
}