AmitDiwan has Published 10744 Articles

Constructing array from string unique characters in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:43:20

144 Views

We are required to write a JavaScript function that takes in a string and starts mapping its characters from 0.And every time, the function encounters a unique (non-duplicate) character it should increase the mapping count by 1 otherwise it should map the same number for duplicate characters.For example: If the ... Read More

Sorting the numbers from within in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:41:09

148 Views

We are required to write a JavaScript function that takes in an array of numbers and reorders the digit of all the numbers internally in a specific order (let’s say in ascending order for the sake of this problem).For example: If the array is −const arr = [543, 65, 343, ... Read More

Number of non-unique characters in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:39:20

221 Views

We are required to write a JavaScript function that takes in a string and returns the count of redundant characters in the string.For example: If the string is −const str = 'abcde'Then the output should be 0.If the string is −const str = 'aaacbfsc';Then the output should be 3.ExampleThe code ... Read More

Dynamic programming to check dynamic behavior of an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:37:29

532 Views

We are required to write a JavaScript function that takes in an array of strings, ordered by ascending length.The function should return true if, for each pair of consecutive strings, the second string can be formed from the first by adding a single letter either at the beginning or end.For ... Read More

Deleting the last vowel from a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:33:36

245 Views

We are required to write a JavaScript function that takes in a string and returns a new string with the last vowel of each word removed.For example: If the string is −const str = 'This is an example string';Then the output should be −const output = 'Ths s n exampl ... Read More

Performing the subtraction operation without the subtraction operator in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:31:45

141 Views

We are required to write a JavaScript function that takes in two numbers and returns their difference but without using the (-) sign.Therefore, let’s write the code for this function −ExampleThe code for this will be −const num1 = 56; const num = 78; const subtractWithoutMinus = (num1, num2) => ... Read More

Picking the odd one out in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:30:24

539 Views

We are required to write a JavaScript function that takes in an array of literals that contains all similar elements but one.Our function should return the unlike number.Therefore, let’s write the code for this function −ExampleThe code for this will be −const arr = [2, 4, 4, 4, 4, 4, ... Read More

Interchanging a string to a binary string in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:25:17

179 Views

We are required to write a JavaScript function that takes in a lowercase string and returns a new string in which all the elements between [a, m] are represented by 0 and all the elements between [n, z] are represented by 1.ExampleThe code for this will be −const str = ... Read More

Finding nearest prime to a specified number in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:23:36

247 Views

We are required to write a JavaScript function that takes in a number and returns the first prime number that appears after n.For example: If the number is 24, then the output should be 29.Therefore, let’s write the code for this function −ExampleThe code for this will be −const num ... Read More

Generating random string of specified length in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:20:28

442 Views

We are required to write a JavaScript function that takes in a number n and returns a random string of length n containing no other than the 26 English lowercase alphabets.Therefore, let’s write the code for this function −ExampleThe code for this will be −const num = 8; const randomNameGenerator ... Read More

Advertisements