This file contains 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
/* | |
Given a string, enclose it in round brackets. | |
Example | |
For inputString = "abacaba", the output should be | |
encloseInBrackets(inputString) = "(abacaba)". | |
*/ | |
function encloseInBrackets(inputString) { |
This file contains 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
/* | |
Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed. | |
Example | |
For statues = [6, 2, 3, 8], the output should be | |
makeArrayConsecutive2(statues) = 3. | |
Ratiorg needs statues of sizes 4, 5 and 7. | |
*/ |
This file contains 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
/* | |
We define the middle of the array arr as follows: | |
if arr contains an odd number of elements, its middle is the element whose index number is the same when counting from the beginning of the array and from its end; | |
if arr contains an even number of elements, its middle is the sum of the two elements whose index numbers when counting from the beginning and from the end of the array differ by one. | |
Given array arr, your task is to find its middle, and, if it consists of two elements, replace those elements with the value of middle. Return the resulting array as the answer. | |
Example | |
For arr = [7, 2, 2, 5, 10, 7], the output should be |
This file contains 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
/* | |
We define the middle of the array arr as follows: | |
if arr contains an odd number of elements, its middle is the element whose index number is the same when counting from the beginning of the array and from its end; | |
if arr contains an even number of elements, its middle is the sum of the two elements whose index numbers when counting from the beginning and from the end of the array differ by one. | |
An array is called smooth if its first and its last elements are equal to one another and to the middle. Given an array arr, determine if it is smooth or not. | |
Example | |
For arr = [7, 2, 2, 5, 10, 7], the output should be |
This file contains 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
/* | |
Remove a part of a given array between given 0-based indexes l and r (inclusive). | |
Example | |
For inputArray = [2, 3, 2, 3, 4, 5], l = 2, and r = 4, the output should be | |
removeArrayPart(inputArray, l, r) = [2, 3, 5]. | |
*/ | |
function removeArrayPart(inputArray, l, r) { |
This file contains 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
/* | |
Given two arrays of integers a and b, obtain the array formed by the elements of a followed by the elements of b. | |
Example | |
For a = [2, 2, 1] and b = [10, 11], the output should be | |
concatenateArrays(a, b) = [2, 2, 1, 10, 11]. | |
*/ | |
function concatenateArrays(a, b) { |
This file contains 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
/* | |
Reversing an array can be a tough task, especially for a novice programmer. Mary just started coding, so she would like to start with something basic at first. Instead of reversing the array entirely, she wants to swap just its first and last elements. | |
Given an array arr, swap its first and last elements and return the resulting array. | |
Example | |
For arr = [1, 2, 3, 4, 5], the output should be | |
firstReverseTry(arr) = [5, 2, 3, 4, 1]. |
This file contains 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
/* | |
Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem. | |
Example | |
For inputArray = [1, 2, 1], elemToReplace = 1, and substitutionElem = 3, the output should be | |
arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3]. | |
*/ |
This file contains 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
/* | |
Given an integer size, return array of length size filled with 1s. | |
Example | |
For size = 4, the output should be | |
createArray(size) = [1, 1, 1, 1]. | |
*/ |
This file contains 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
/* | |
Determine if the given character is a digit or not. | |
Example | |
For symbol = '0', the output should be | |
isDigit(symbol) = true; | |
For symbol = '-', the output should be | |
isDigit(symbol) = false. | |
*/ |