2018-10-10 18:03:03 -04:00
---
title: Compare a list of strings
id: 596e457071c35c882915b3e4
challengeType: 5
2019-08-28 16:26:13 +03:00
forumTopicId: 302235
2018-10-10 18:03:03 -04:00
localeTitle: Сравнить список строк
---
## Description
2019-08-28 16:26:13 +03:00
<section id='description'>
<p> Учитывая <a href="https://en.wikipedia.org/wiki/List_(abstract_data_type)" title="wp: List_ (abstract_data_type)">список</a> произвольно многих строк, реализуйте функцию для каждого из следующих условий: </p> если все они лексически равны, если каждая строка лексически меньше, чем одна после нее (т. е . является ли список в строгом порядке)
</section>
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
<section id='instructions'>
2018-10-10 18:03:03 -04:00
</section>
## Tests
<section id='tests'>
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: <code>allEqual</code> is a function.
testString: assert(typeof allEqual === 'function');
- text: <code>azSorted</code> is a function.
testString: assert(typeof azSorted === 'function');
- text: <code>allEqual(["AA", "AA", "AA", "AA"])</code> returns true.
testString: assert(allEqual(testCases[0]));
- text: <code>azSorted(["AA", "AA", "AA", "AA"])</code> returns false.
testString: assert(!azSorted(testCases[0]));
- text: <code>allEqual(["AA", "ACB", "BB", "CC"])</code> returns false.
testString: assert(!allEqual(testCases[1]));
- text: <code>azSorted(["AA", "ACB", "BB", "CC"])</code> returns true.
testString: assert(azSorted(testCases[1]));
- text: <code>allEqual([])</code> returns true.
testString: assert(allEqual(testCases[2]));
- text: <code>azSorted([])</code> returns true.
testString: assert(azSorted(testCases[2]));
- text: <code>allEqual(["AA"])</code> returns true.
testString: assert(allEqual(testCases[3]));
- text: <code>azSorted(["AA"])</code> returns true.
testString: assert(azSorted(testCases[3]));
- text: <code>allEqual(["BB", "AA"])</code> returns false.
testString: assert(!allEqual(testCases[4]));
- text: <code>azSorted(["BB", "AA"])</code> returns false.
testString: assert(!azSorted(testCases[4]));
2018-10-10 18:03:03 -04:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
2019-08-28 16:26:13 +03:00
function allEqual(arr) {
2018-10-10 18:03:03 -04:00
// Good luck!
return true;
}
2019-08-28 16:26:13 +03:00
function azSorted(arr) {
2018-10-10 18:03:03 -04:00
// Good luck!
return true;
}
```
</div>
2019-08-28 16:26:13 +03:00
### After Tests
2018-10-10 18:03:03 -04:00
<div id='js-teardown'>
```js
2019-08-28 16:26:13 +03:00
const testCases = [['AA', 'AA', 'AA', 'AA'], ['AA', 'ACB', 'BB', 'CC'], [], ['AA'], ['BB', 'AA']];
2018-10-10 18:03:03 -04:00
```
</div>
</section>
## Solution
<section id='solution'>
```js
2019-08-28 16:26:13 +03:00
function allEqual(a) {
let out = true;
let i = 0;
while (++i < a.length) {
out = out && (a[i - 1] === a[i]);
} return out;
}
function azSorted(a) {
let out = true;
let i = 0;
while (++i < a.length) {
out = out && (a[i - 1] < a[i]);
} return out;
}
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
</section>