2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: af7588ade1100bde429baf20
|
2021-01-12 08:18:51 -08:00
|
|
|
title: 寻找缺失的字母
|
2020-12-16 00:37:30 -07:00
|
|
|
challengeType: 5
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: missing-letters
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
在这道题目中,我们需要写一个函数,找出传入的字符串里缺失的字母并返回它。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
判断缺失的依据是字母顺序。对于没有缺失的情况,请返回 `undefined`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`fearNotLetter("abce")` 应返回 "d"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.deepEqual(fearNotLetter('abce'), 'd');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`fearNotLetter("abcdefghjklmno")` 应返回 "i"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert.deepEqual(fearNotLetter('abcdefghjklmno'), 'i');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`fearNotLetter("stvwx")` 应返回 "u"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert.deepEqual(fearNotLetter('stvwx'), 'u');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`fearNotLetter("bcdf")` 应返回 "e"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert.deepEqual(fearNotLetter('bcdf'), 'e');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`fearNotLetter("abcdefghijklmnopqrstuvwxyz")` 应返回 undefined。
|
2020-09-07 16:10:29 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.isUndefined(fearNotLetter('abcdefghijklmnopqrstuvwxyz'));
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function fearNotLetter(str) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
fearNotLetter("abce");
|
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```js
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
```
|