AmitDiwan has Published 10744 Articles

Converting string to a binary string - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:04:13

653 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.ExampleFollowing is the code −const str = 'Hello worlld ... Read More

Finding greatest digit by recursion - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:02:46

314 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 6ExampleFollowing is the code −const num = 45654356; const greatestDigit = (num = 0, greatest = 0) ... Read More

Calculating resistance of n devices - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:01:45

222 Views

In Physics, the equivalent resistance of say 3 resistors connected in series is given by −R = R1 + R2 + R3And the equivalent resistance of resistors connected in parallel is given by −R = (1/R1) + (1/R2) + (1/R3)We are required to write a JavaScript function that takes a ... Read More

Distance to nearest vowel in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:00:07

462 Views

We are required to write a JavaScript function that takes in a string with atleast 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';Then the ... Read More

Valid triangle edges - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 09:58:25

464 Views

Suppose, we have three lines of length, respectively l, m and n. These three lines can only form a triangle, if the sum of any arbitrary two sides is greater than the third side.For example, if the length of three lines is 4, 9 and 3, they cannot form a ... Read More

Casting a string to snake case - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 09:57:22

2K+ Views

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

Return index of first repeating character in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 09:56:20

217 Views

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

Find the dissimilarities in two strings - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 09:54:57

142 Views

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

Reverse only the odd length words - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 09:53:47

521 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an odd number of characters in them.Any substring in the string qualifies to be a word, if either it is encapsulated by two spaces on either ends or ... Read More

Reverse word starting with particular characters - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 09:52:22

230 Views

We are required to write a JavaScript function that takes in a sentence string and a character and the function should reverse all the words in the string starting with that particular character.For example: If the string is −const str = 'hello world, how are you';Starting with a particular character ... Read More

Advertisements