AmitDiwan has Published 10740 Articles

Greatest digit of a number in JavaScript

AmitDiwan

AmitDiwan

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

593 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

138 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

216 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

603 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

484 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

381 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

166 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

138 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

306 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

Finding place value of a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 09:13:31

834 Views

We are required to write a function, let’s say splitNumber() that takes in a positive integer and returns an array populated with the place values of all the digits of the number.For example −If the input number is −const num = 1234;OutputThen the output should be −const output = [1000, ... Read More

Advertisements