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 manipulate(arrInput) { | |
| let arrayWork = arrInput[0].split(' ').map(Number); | |
| arrInput.shift() | |
| for (let i = 0; i < arrInput.length; i++) { | |
| let command = arrInput[i].split(' '); | |
| if (command[1] === 'even') { | |
| if (command[0] === 'max') { | |
| if (max(even(arrayWork)) < 0) { | |
| console.log('No matches'); |
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 solve(arr) { | |
| let resultArray = [+arr[0]]; | |
| let check = +arr[0] | |
| for (let i = 1; i < arr.length; i++) { | |
| if (arr[i] >= check) { | |
| resultArray.push(+arr[i]); | |
| check = +arr[i] | |
| } | |
| } | |
| console.log(resultArray.join(' ')) |
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 solve(arr1, arr2) { | |
| let resultArr = arr1.map(function(e, i) { | |
| return e - arr2[i]; | |
| }); | |
| let sum = arr1.map(Number).reduce((a, b) => a + b); | |
| let check = resultArr.filter(el => el != 0) | |
| console.log(check.length > 0 ? | |
| `Arrays are not identical. Found difference at ${resultArr.indexOf(check[0])} index` : | |
| `Arrays are identical. Sum: ${sum}`); |
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 solve(arr) { | |
| let isTrue = true; | |
| let rowCheck = arr[0].reduce((a, b) => a + b, 0); | |
| for (let i = 0; i < arr.length; i++) { | |
| let checkSum = arr[i].reduce((a, b) => a + b, 0); | |
| if (checkSum !== rowCheck) { | |
| isTrue = false; | |
| break; | |
| } |
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 solve(arr) { | |
| let sequenceArray = arr.slice(1, arr.length).map(x => x.split('!').join('')); | |
| let sequenceArray1 = sequenceArray.map(x => x.split('0')); | |
| let searchString = '' | |
| let searchIndex = sequenceArray.length; | |
| let searchSum = 0; | |
| let searchSequence = '0'.repeat(arr[0]) | |
| let searchSequenceIndex = 0 | |
| for (let index in sequenceArray1) { |
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 solve(arr) { | |
| let lengthSequences = Number(arr[0]); | |
| let sequenceArray = arr.slice(1, arr.length) | |
| .map(x => x.split('!').join('')); | |
| let searchString = '1'.repeat(lengthSequences); | |
| let sequenceNum = 0; | |
| let sequenceResult = ''; | |
| let resultSum = 0; | |
| while (sequenceNum == 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
| function solve(arr) { | |
| let rotations = +arr[arr.length-1]; | |
| arr.pop() | |
| if (isNaN(rotations)){ | |
| console.log('Empty'); | |
| } else { | |
| for (let i = 1; i <= rotations; i++) { | |
| arr.unshift(arr.pop()); | |
| } |
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 solve(arr) { | |
| let resultArray = []; | |
| for (let wordIndex in arr) { | |
| if (arr[wordIndex] === 'add') { | |
| resultArray.push(+wordIndex +1); | |
| } else { | |
| resultArray.pop() | |
| } | |
| } | |
| if (resultArray.length > 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
| list1 = [1, 2, 3, 2, 1, 1, 5, 6] | |
| list2 = ['aa', 'bb', 'cc', 'aa', 'dd', 'ff', 'aa', 'gd'] | |
| min_index1 = list(filter(lambda x: x[1]==min(list1), enumerate(list1)))[-1][0] | |
| min_index2 = list(filter(lambda x: x[1]==min(list2), enumerate(list2)))[-1][0] | |
| print(min_index1) | |
| print(min_index2) |
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
| import re | |
| def create_string(indexes, string): | |
| result_list = [' '] * len(indexes) | |
| for i in range(0, len(result_list)): | |
| if indexes[i] <= len(string) - 1: | |
| result_list[i] = string[indexes[i]] | |
| print_string = ''.join(result_list) | |
| return print_string |
NewerOlder