AmitDiwan has Published 10744 Articles

Constructing product array in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Dec-2020 08:14:15

602 Views

We are required to write a JavaScript function that takes in an array of Numbers. The function should construct a new array based on the original array. Each corresponding element of the new array should be the product of all the elements of the original array including that element.For example ... Read More

Get the closest number out of an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Dec-2020 08:00:27

154 Views

We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a single number as the second argument.The function should find and return that number from the array which is closest to the number specified by the second argument.For example −const ... Read More

Sum of all multiples in JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 12:09:24

268 Views

We are required to write a JavaScript function that takes in a number, say n, as the first argument, and then any number of arguments following that.The idea is to sum all numbers upto n which are divided by any of the numbers specified by second argument and after.For example ... Read More

Sum up a number until it becomes 1 digit JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 12:03:49

199 Views

We are required to write a JavaScript function that takes in a Number as the only input. The function should do one simple thing −keep adding the resultant digits until they converse to a single digit number.For example −const num = 5798;i.e.5 + 7 + 9 + 8 = 29 ... Read More

Dash separated cartesian product of any number of arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 11:35:37

181 Views

We are required to write a JavaScript function that takes in any number of arrays of literals. The function should compute and return an array of cartesian product of all the elements from the arrays separating them with a dash('−').ExampleThe code for this will be −const arr1= [ 'a', 'b', ... Read More

Finding Number of Days Between Two Dates JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 07:54:45

224 Views

We are required to write a JavaScript function that takes in two dates in the 'YYYY-MM-DD' format as the first and second argument respectively. The function should then calculate and return the number of days between the two dates.For example −If the input dates are −const str1 = '2020-05-21'; const ... Read More

Lucky Numbers in a Matrix in JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 07:01:27

610 Views

Given a m * n matrix of distinct numbers, we have to return all lucky numbers in the 2-D array (matrix) in any order.A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.For example − If ... Read More

JavaScript - find distance between items on array

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 06:49:52

322 Views

Suppose, we have a sorted (increasing order) array of Numbers like this −const arr = [2, 5, 7, 8, 9];We are required to write a JavaScript function that takes in one such array. The function should construct a new subarray for each element of the input array.The sub-array should contain ... Read More

Finding number of spaces in a string JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 05:23:36

1K+ Views

We are required to write a JavaScript function that takes in a string containing spaces. The function should simply count the number of spaces present in that string.For example −If the input string is −const str = 'this is a string';Then the output should be −const output = 4;Exampleconst str ... Read More

Sorting array of Number by increasing frequency JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Nov-2020 05:14:30

1K+ Views

We are required to write a JavaScript function that takes in an array of numbers that might contain some repeating numbers.The function should sort the array such that the elements that are repeated for the least number of times appears first followed by the elements with increasing frequency.For example −If ... Read More

Advertisements