AmitDiwan has Published 10744 Articles

Return 5 random numbers in range, first number cannot be zero - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:37:35

149 Views

We are required to write a JavaScript function that generates an array of exactly five unique random numbers. The condition is that all the numbers have to be in the range [0, 9] and the first number cannot be 0.ExampleFollowing is the code −const fiveRandoms = () => {   ... Read More

How to replace leading zero with spaces - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:36:30

322 Views

We are required to write a JavaScript function that takes in a string that represents a number. Replace the leading zero with spaces in the number. We need to make sure the prior spaces in number are retained.For example, If the string value is defined as −"   004590808"Then the ... Read More

Finding square root of a number without using library functions - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:35:30

611 Views

We are required to write a JavaScript function that takes in a number and calculates its square root without using the Math.sqrt() function.ExampleFollowing is the code −const square = (n, i, j) => {    let mid = (i + j) / 2;    let mul = mid * mid; ... Read More

Trying to get number for each character in string - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:34:18

217 Views

We are required to write a JavaScript function that takes in a string. It should print out each number for every corresponding letter in the string.For example, a = 1 b = 2 c = 3 d = 4 e = 5 . . . Y = 25 Z = ... Read More

Counting numbers after decimal point in JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:33:12

2K+ Views

We are required to write a JavaScript function that takes in a number which may be an integer or a floating-point number. If it's a floating-point number, we have to return the count of numbers after the decimal point. Otherwise we should return 0.For our example, we are considering two ... Read More

How to get the numbers which can divide all values in an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:32:22

449 Views

We are required to write a JavaScript function that takes in an array of numbers and returns a number which can exactly divide all the numbers in the array.Let’s say the following is our array −const arr = [4, 6, 34, 76, 78, 44, 34, 26, 88, 76, 42];ExampleFollowing is ... Read More

Sorting Array with JavaScript reduce function - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:31:21

1K+ Views

We are required to write a JavaScript function that takes in an array of numbers. The function should sort the array with using the Array.prototype.sort() method. We are required to use the Array.prototype.reduce() method to sort the array.Let’s say the following is our array −const arr = [4, 56, 5, ... Read More

Square every digit of a number - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:30:20

415 Views

We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenatedFor example: If the number is −9119Then the output should be −811181because 9^2 is 81 and 1^2 is 1.ExampleFollowing is ... Read More

Shift certain array elements to front of array - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:29:27

215 Views

We are required to write a JavaScript function takes in an array of numbers. The function should bring all the 3-digit integers to the front of the array.Let’s say the following is our array of numbers −const numList = [1, 324, 34, 3434, 304, 2929, 23, 444];ExampleFollowing is the code ... Read More

Finding intersection of multiple arrays - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:22:16

1K+ Views

We are required to write a JavaScript function that takes in any arbitrary number of arrays and returns an array of elements that are common to all arrays. If there are no common elements, then we should return an empty array.Let’s say the following are our arrays −const arr1 = ... Read More

Advertisements