AmitDiwan has Published 10744 Articles

Column sum of elements of 2-D arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:21:06

1K+ Views

We have an array of arrays and are required to write a function that takes in this array and returns a new array that represents the sum of corresponding elements of original array.If the original array is −[    [43, 2, 21],    [1, 2, 4, 54],    [5, 84, ... Read More

Greatest digit of a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:17:18

565 Views

We are required to write a JavaScript recursive function that takes in a number and returns the greatest digit in the number.For example: If the number is 45654356Then the return value should be 6ExampleThe code for this will be −const num = 45654356; const greatestDigit = (num = 0, greatest ... Read More

Vowel gaps array in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:12:31

117 Views

We are required to write a JavaScript function that takes in a string with at least one vowel, and for each character in the string we have to map a number in a string representing its nearest distance from a vowel.For example: If the string is −const str = 'vatghvf';OutputThen ... Read More

Changing the case of a string using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:10:37

180 Views

We are required to write a JavaScript function that takes in a string and converts it to snake case.Snake case is basically a style of writing strings by replacing the spaces with '_' and converting the first letter of each word to lowercase.ExampleThe code for this will be −const str ... Read More

Finding the index of the first repeating character in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:09:17

578 Views

We are required to write a JavaScript function that takes in a string and returns the index of the first character that appears twice in the string. If there is no such character then we should return -1.Let’s say the following is our string −const str = 'Hello world, how ... Read More

Differences in two strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:05:21

447 Views

We are required to write a JavaScript function that takes in two strings and find the number of corresponding dissimilarities in the strings. The corresponding elements will be dissimilar if they are not equalExampleLet’s say the following are our strings −const str1 = 'Hello world!!!'; const str2 = 'Hellp world111';ExampleThe ... Read More

Reversing the even length words of a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:03:58

356 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an even number of characters in them.Let’s say the following is our string −const str = 'This is an example string';We want to reverse the even length words ... Read More

Finding the index of the first element that violates the series (first non-consecutive number) in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:02:26

139 Views

We have to write a function that takes in an array and returns the index of the first nonconsecutive number from it.Like all the numbers will be in an arithmetic progression of common difference 1. But the number, which violates this rule, we have to return its index. If all ... Read More

Building an array from a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 09:16:03

121 Views

We have to write a function that creates an array with elements repeating from the string till the limit is reached.Suppose there is a string ‘aba’ and a limit 5.e.g. string = "string" and limit = 8 will give new arrayconst arr = ["s", "t", "r", "i", "n", “g”, “s”, ... Read More

Code to construct an object from a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 09:14:18

266 Views

We are required to write a function that takes in a string as the first and the only argument and constructs an object with its keys based on the unique characters of the string and value of each key being defaulted to 0.For example: If the input string is −const ... Read More

Advertisements