From 3462c97d1adf5712672bb2a17dd22754c0992813 Mon Sep 17 00:00:00 2001 From: Nikolay Gagarinov Date: Wed, 5 Aug 2026 20:05:11 +0500 Subject: [PATCH] clarify the filter() return type in the generic-functions exercise (#269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The task said push() and filter() match the signature of Array methods, while filter() has to return MyArray rather than T[] — otherwise the newColl.items line from the very same example does not type-check. Now the text spells out what matches (the callback parameters) and what differs (the return type), so a student arrives at the same signature as the teacher's solution. The type and the test are unchanged. Co-Authored-By: Claude Opus 5 (1M context) --- modules/40-generics/30-generic-functions/en/EXERCISE.md | 4 +++- modules/40-generics/30-generic-functions/ru/EXERCISE.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/40-generics/30-generic-functions/en/EXERCISE.md b/modules/40-generics/30-generic-functions/en/EXERCISE.md index c2a07bc0..4fb67e42 100644 --- a/modules/40-generics/30-generic-functions/en/EXERCISE.md +++ b/modules/40-generics/30-generic-functions/en/EXERCISE.md @@ -11,4 +11,6 @@ const newColl = coll.filter((value) => value % 2 == 0); console.log(newColl.items); // [10] ``` -The type includes two methods: [push()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) and [filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter), matching the signature of Array methods. The data inside should be stored in the `items` property. For `push()`, accept the convention that the method takes only one parameter. Ignore the other parameters. +The type includes two methods: [push()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) and [filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). `push()` takes a value of the same type as the collection elements — unlike the `Array` method, accept the convention that there is only one parameter. `filter()` takes a callback with the same parameters as the method of the same name in `Array`: `value`, `index`, and `array`. The data inside should be stored in the `items` property. + +The return values, however, do not match completely. `push()`, just like in `Array`, returns the new length of the collection. But `filter()` returns not an array — it returns a new collection of the `MyArray` type. That is why the result of filtering in the example above has the `items` property. diff --git a/modules/40-generics/30-generic-functions/ru/EXERCISE.md b/modules/40-generics/30-generic-functions/ru/EXERCISE.md index 5311124a..4fea228b 100644 --- a/modules/40-generics/30-generic-functions/ru/EXERCISE.md +++ b/modules/40-generics/30-generic-functions/ru/EXERCISE.md @@ -11,4 +11,6 @@ const newColl = coll.filter((value) => value % 2 == 0); console.log(newColl.items); // [10] ``` -Тип включает в себя два метода: [push()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) и [filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter), совпадающие по сигнатуре с методами Array. Данные внутри должны храниться в свойстве `items`. Для `push()` примем соглашение, что метод принимает только один параметр. Игнорируйте остальные параметры. +Тип включает в себя два метода: [push()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) и [filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). `push()` принимает значение того же типа, что и элементы коллекции — в отличие от метода `Array`, примем соглашение, что параметр только один. `filter()` принимает колбек с такими же параметрами, как у одноименного метода `Array`: `value`, `index` и `array`. Данные внутри должны храниться в свойстве `items`. + +А вот возвращаемые значения совпадают не полностью. `push()`, как и в `Array`, возвращает новую длину коллекции. `filter()` же возвращает не массив, а новую коллекцию типа `MyArray` — поэтому в примере выше у результата фильтрации есть свойство `items`.