This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Сделайте из него массив, состоящий из квадратов этих чисел. | |
| function square(arr) { | |
| const result = arr.map(it => it * it) | |
| return result | |
| } | |
| //Верните массив, состоящий только из уникальных значений(убрать все дубликаты, число в новом массиве не должно повторяться) | |
| function noDuplicates(arr) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const str = 'Привет123 как де123456ла 656748привет' | |
| const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
| splittedStr = str.split('') | |
| for (let i = 0; i < str.length; i++) { | |
| if (!(splittedStr[i] in numbers)) [ | |
| splittedStr[i] = ' ' | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let str = 'Привет как дела привет' | |
| splittedStr = str.split(' ') | |
| result = splittedStr.filter(it => it.length > 4) | |
| console.log(result.length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [1, 2, [3, 4], 5, {a: 7}] | |
| console.log(arr.filter(it => typeof it === "object").filter(it => Array.isArray(it))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [11, 2, 2] | |
| let result = arr.reduce( | |
| (acc, rec) => acc + rec, | |
| 0 | |
| ) | |
| console.log(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [11, -2, 2, -33] | |
| console.log(arr.filter(it => it < 0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [11, -2, 2, 3] | |
| let flag = true | |
| for (let i = 0; i < arr.length; i++) { | |
| if (arr[i] < 0) { | |
| flag = false | |
| break | |
| } | |
| } | |
| console.log(flag) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [1, 2, 2, 3] | |
| console.log(arr.filter(( it, index ) => arr.indexOf(it) === index)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [1, 2, 3] | |
| console.log(arr.map(it => it * it)) |