Skip to content

Commit 0ad45aa

Browse files
authored
Merge pull request #679 from hexlet-basics/change-exercise
change exercise
2 parents bdd8f28 + 6172a46 commit 0ad45aa

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

modules/50-loops/28-build-strings/description.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ theory: |
4141
4242
instructions: |
4343
44-
Write the same `reverse()` function, except it doesn't iterate over a string from the first element to the last, but vice versa, from the last to the first. The overall structure of the function remains the same. The initial index, the loop termination condition, the building of a new string, and the formation of a new index in the loop will change, however.
44+
Write the function `even()` that returns a new string consisting of even characters from the original string
4545
4646
tips: []

modules/50-loops/28-build-strings/description.ru.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ theory: |
4141
4242
instructions: |
4343
44-
Реализуйте такую же функцию `reverse()`, но выполняющую обход строки не с первого элемента по последний, а наоборот, от последнего к первому. Общая структура функции при этом останется такой же. Изменится начальный индекс, условие окончания цикла, сборка новой строки и формирование нового индекса в цикле.
44+
Реализуйте функцию `even()`, которая возвращает новую строку, состоящую из чётных символов исходной строки.
4545
4646
tips: []
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/* eslint operator-assignment: 0 */
22

33
// BEGIN
4-
const reverse = (str) => {
5-
let i = str.length - 1;
4+
const even = (str) => {
5+
let i = 0;
66
let result = '';
7-
while (i >= 0) {
8-
result = `${result}${str[i]}`;
9-
i = i - 1;
7+
while (i < str.length) {
8+
if (i % 2 !== 0) {
9+
result = `${result}${str[i]}`;
10+
}
11+
i = i + 1;
1012
}
1113

1214
return result;
1315
};
1416

1517
// END
1618

17-
export default reverse;
19+
export default even;

modules/50-loops/28-build-strings/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { test, expect } from '@jest/globals';
22
import f from './index.js';
33

44
test('test', () => {
5-
expect(f('Bran')).toEqual('narB');
5+
expect(f('Bran')).toEqual('rn');
66
expect(f('')).toEqual('');
7-
expect(f('Hexlet')).toEqual('telxeH');
7+
expect(f('Hexlet')).toEqual('elt');
88
});

0 commit comments

Comments
 (0)