zadanieb9512 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +21 -0
  2. package/package.json +16 -0
  3. package/test.js +4 -0
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ // Функция: сумма элементов массива
2
+ function sumArray(arr) {
3
+ if (!Array.isArray(arr)) {
4
+ throw new TypeError('Ожидался массив');
5
+ }
6
+ return arr.reduce((sum, value) => sum + Number(value || 0), 0);
7
+ }
8
+
9
+ // Функция: уникальные элементы массива
10
+ function uniqueArray(arr) {
11
+ if (!Array.isArray(arr)) {
12
+ throw new TypeError('Ожидался массив');
13
+ }
14
+ return Array.from(new Set(arr));
15
+ }
16
+
17
+ // Обязательно экспортируем функции, чтобы ими могли пользоваться другие
18
+ module.exports = {
19
+ sumArray,
20
+ uniqueArray,
21
+ };
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "zadanieb9512",
3
+ "version": "1.0.0",
4
+ "description": "test_1",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "toster-tester",
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "not_remember"
15
+ }
16
+ }
package/test.js ADDED
@@ -0,0 +1,4 @@
1
+ const { sumArray, uniqueArray } = require('./index');
2
+
3
+ console.log(sumArray([1, 2, 3])); // должно вывести 6
4
+ console.log(uniqueArray([1, 2, 2, 3, 3])); // должно вывести [1, 2, 3]