AmitDiwan has Published 10744 Articles

JavaScript function that generates all possible combinations of a string

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:45:26

789 Views

We are required to write a JavaScript function that takes in a string as the only argument. The function should generate an array of strings that contains all possible contiguous substrings that exist in the array.ExampleFollowing is the code −const str = 'Delhi'; const allCombinations = (str1 = '') => ... Read More

JavaScript function to convert Indian currency numbers to words with paise support

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:44:14

3K+ Views

We are required to write a JavaScript function that takes in a floating-point number up to 2 digits of precision.The function should convert that number into the Indian current text.For example −If the input number is −const num = 12500Then the output should be −const output = 'Twelve Thousand Five ... Read More

Calculate the hypotenuse of a right triangle in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:40:27

709 Views

We are required to write a JavaScript function that takes in two numbers. The first number represents the length of the base of a right triangle and the second is perpendicular. The function should then compute the length of the hypotenuse based on these values.For example −If base = 8, ... Read More

Converting ASCII to hexadecimal in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:38:13

900 Views

We are required to write a JavaScript function that takes in a string that represents a ASCII number. The function should convert the number into its corresponding hexadecimal code and return the hexadecimal.For example −f the input ASCII string is −const str = '159';Then the hexadecimal code for this should ... Read More

Finding union of two sets in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:37:06

1K+ Views

Union SetUnion Set is the set made by combining the elements of two sets. Therefore, the union of sets A and B is the set of elements in A, or B, or both.For example −If we have two sets denoted by two arrays like this −const arr1 = [1, 2, ... Read More

Flattening a deeply nested array of literals in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:35:47

377 Views

We are required to write a JavaScript function that takes in a nested array of literals as the only argument. The function should construct a new array that contains all the literal elements present in the input array but without nesting.For example −If the input array is −const arr = ... Read More

Difference between sum and product of an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:34:33

213 Views

We are required to write a JavaScript function that takes in an array of Numbers as the only argument. The function should calculate the sum of all numbers in the array and the product of all numbers. Then the function should return the absolute difference between the sum and the ... Read More

Are mean mode of a dataset equal in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:33:11

181 Views

We are required to write a JavaScript function that takes in an array of sorted numbers. The function should calculate the mean and the mode of the dataset. Then if the mean and mode are equal, the function should return true, false otherwise.For example −If the input array is −const ... Read More

Finding the longest word in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:32:03

428 Views

We are required to write a JavaScript function that takes in a string as the only argument. The function should then iterate through the string and find and return the longest word from the string.For example −If the input string is −const str = 'Coding in JavaScript is really fun';Then ... Read More

Reversing a string using for loop in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:31:02

2K+ Views

We are required to write a JavaScript function that takes in a string as the only argument. The function should construct a new reversed string based on the input string using the for a loop.ExampleFollowing is the code −const str = 'this is the original string'; const reverseString = (str ... Read More

Advertisements