2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: af2170cad53daa0770fabdea
|
2021-03-13 17:31:57 +00:00
|
|
|
title: 比较字符串
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 5
|
2021-01-12 16:18:51 +00:00
|
|
|
forumTopicId: 16025
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: mutations
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
如果数组里的第一个字符串包含了第二个字符串中的所有字母,则返回 `true`。
|
2021-01-12 16:18:51 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
例如,`["hello", "Hello"]` 应该返回 `true`。因为在忽略大小写的情况下,第一个字符串包含了第二个字符串里出现的所有字母。
|
2021-01-12 16:18:51 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`["hello", "hey"]` 应该返回 `false`。因为 `hello` 并不包含字符 `y`。
|
2021-01-12 16:18:51 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
最后,`["Alien", "line"]` 应该返回 `true`。因为 `line` 中的所有字母都出现在了 `Alien` 中。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --hints--
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["hello", "hey"])` 应返回 `false`。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['hello', 'hey']) === false);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["hello", "Hello"])` 应返回 `true`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(mutation(['hello', 'Hello']) === true);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])` 应返回 `true`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
```js
|
2020-12-16 07:37:30 +00:00
|
|
|
assert(mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu']) === true);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["Mary", "Army"])` 应返回 `true`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(mutation(['Mary', 'Army']) === true);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["Mary", "Aarmy"])` 应返回 `true`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(mutation(['Mary', 'Aarmy']) === true);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["Alien", "line"])` 应返回 `true`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(mutation(['Alien', 'line']) === true);
|
|
|
|
```
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["floor", "for"])` 应返回 `true`。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['floor', 'for']) === true);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["hello", "neo"])` 应返回 `false`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
```js
|
2020-12-16 07:37:30 +00:00
|
|
|
assert(mutation(['hello', 'neo']) === false);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
2020-08-13 15:24:35 +00:00
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["voodoo", "no"])` 应返回 `false`。
|
2021-01-12 16:18:51 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['voodoo', 'no']) === false);
|
|
|
|
```
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["ate", "date"])` 应返回 `false`。
|
2021-01-12 16:18:51 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['ate', 'date']) === false);
|
|
|
|
```
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["Tiger", "Zebra"])` 应返回 `false`。
|
2021-01-12 16:18:51 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['Tiger', 'Zebra']) === false);
|
|
|
|
```
|
|
|
|
|
2021-03-13 17:31:57 +00:00
|
|
|
`mutation(["Noel", "Ole"])` 应返回 `true`。
|
2021-01-12 16:18:51 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['Noel', 'Ole']) === true);
|
|
|
|
```
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function mutation(arr) {
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutation(["hello", "hey"]);
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```js
|
|
|
|
function mutation(arr) {
|
|
|
|
let hash = Object.create(null);
|
|
|
|
|
|
|
|
arr[0].toLowerCase().split('').forEach(c => hash[c] = true);
|
|
|
|
|
|
|
|
return !arr[1].toLowerCase().split('').filter(c => !hash[c]).length;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutation(["hello", "hey"]);
|
|
|
|
```
|