2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: af7588ade1100bde429baf20
|
|
|
|
challengeType: 5
|
2020-10-01 17:54:21 +02:00
|
|
|
title: 丢失的字母
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-09-07 16:10:29 +08:00
|
|
|
<section id='description'>
|
|
|
|
在这道题目中,我们需要写一个函数,找到传入的字符串里缺失的字母并返回它。
|
|
|
|
判断缺失的依据是字母顺序,比如 abcdfg 中缺失了 e。而 abcdef 中就没有字母缺失,此时我们需要返回<code>undefined</code>。
|
|
|
|
如果你遇到了问题,请点击<a href='https://forum.freecodecamp.one/t/topic/157' target='_blank'>帮助</a>。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
2020-09-07 16:10:29 +08:00
|
|
|
<section id='instructions'>
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
2020-09-07 16:10:29 +08:00
|
|
|
- text: "<code>fearNotLetter('abce')</code>应该返回 'd'。"
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(fearNotLetter('abce'), 'd');
|
2020-09-07 16:10:29 +08:00
|
|
|
- text: "<code>fearNotLetter('abcdefghjklmno')</code>应该返回 'i'。"
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(fearNotLetter('abcdefghjklmno'), 'i');
|
2020-09-07 16:10:29 +08:00
|
|
|
- text: "<code>fearNotLetter('stvwx')</code>应该返回 'u'。"
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(fearNotLetter('stvwx'), 'u');
|
2020-09-07 16:10:29 +08:00
|
|
|
- text: "<code>fearNotLetter('bcdf')</code>应该返回 'e'。"
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(fearNotLetter('bcdf'), 'e');
|
2020-09-07 16:10:29 +08:00
|
|
|
- text: "<code>fearNotLetter('abcdefghijklmnopqrstuvwxyz')</code>应该返回<code>undefined</code>。"
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.isUndefined(fearNotLetter('abcdefghijklmnopqrstuvwxyz'));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function fearNotLetter(str) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
fearNotLetter("abce");
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
2020-09-07 16:10:29 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
```js
|
2020-09-07 16:10:29 +08:00
|
|
|
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;
|
|
|
|
}
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2020-09-07 16:10:29 +08:00
|
|
|
</section>
|