AmitDiwan has Published 10744 Articles

Finding place value of a number in JavaScript

AmitDiwan

AmitDiwan

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

815 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

Rounding off numbers to some nearest power in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 09:08:38

178 Views

We are required to write a JavaScript function that takes in a number and returns a number that can be represented as a power of 2 which is nearest to the input number.For example: If the input number if 145.Then the output should be 128 because 145 is the nearest ... Read More

Searching for a query using binary search in JavaScript

AmitDiwan

AmitDiwan

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

206 Views

We are required to write a JavaScript function that takes in a sorted array of literals as the first argument and a query literal as second. Then our function should make use of the Binary Search algorithm to find whether the query exists in the array or not.If it exists, ... Read More

Computing zeroes (solutions) of a mathematical equation in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 09:01:46

115 Views

We are required to write a JavaScript function that takes in three numbers (representing the coefficient of quadratic term, coefficient of linear term and the constant respectively in a quadratic quadratic).And we are required to find the roots, (if they are real roots) otherwise we have to return false.ExampleThe code ... Read More

Keeping only redundant words in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 08:59:48

419 Views

We are required to write a JavaScript function that takes in a string and returns a new string with only the words that appeared for more than once in the original string.For example:If the input string is −const str = 'this is a is this string that contains that some ... Read More

Program to implement Bucket Sort in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:37:17

684 Views

The Bucket Sort works by splitting the array of size n into k buckets which holds a specific range of element values.Then, these buckets are then sorted using a sorting algorithm which can be chosen based on the expected input size.We can describe this algorithm as follows −Algorithm:Create the initial ... Read More

Algorithm for matrix multiplication in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:34:04

2K+ Views

We are required to write a JavaScript function that takes in two 2-D arrays of numbers and returns their matrix multiplication result.Let’s write the code for this function −ExampleThe code for this will be −const multiplyMatrices = (a, b) => {    if (!Array.isArray(a) || !Array.isArray(b) || !a.length || !b.length) ... Read More

Alternate casing a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:31:56

1K+ Views

We are required to write a JavaScript function that takes in a string and constructs a new string with all the uppercase characters from the original string converted to lowercase and all the lowercase characters converted to uppercase from the original string.For example: If the string is −const str = ... Read More

Prime factor array of a Number in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:30:04

329 Views

We are required to write a JavaScript function that takes in a number and returns an array of all the prime numbers that exactly divide the input number.For example, if the input number is 105.Then the output should be −const output = [3, 5, 7];ExampleThe code for this will be ... Read More

Shedding a string off whitespaces in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:28:32

161 Views

We are required to write a JavaScript function that takes in a string and returns a new string with all the character of the original string just the whitespaces removed.ExampleThe code for this will be −const str = "This is an example string from which all whitespaces will be removed"; ... Read More

Advertisements