AmitDiwan has Published 10744 Articles

Summing cubes of natural numbers within a range in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:52:13

162 Views

ProblemWe are required to write a JavaScript function that takes in a range array of two numbers. Our function should find the sum of all the cubes of the numbers that falls in the specified range.ExampleFollowing is the code − Live Democonst range = [4, 11]; const sumCubes = ([l, h]) ... Read More

Calculating and adding the parity bit to a binary using JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:51:26

693 Views

Parity BitA parity bit, or check bit, is a bit added to a string of bits to ensure that the total number of 1-bits in the string is even or odd.ProblemWe are required to write a JavaScript function that takes in two parameters, one being the wanted parity (always 'even' ... Read More

Sorting binary string having an even decimal value using JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:49:07

188 Views

ProblemWe are required to write a JavaScript function that takes in a string that contains binary strings of length 3 all separated by spaces.Our function should sort the numbers in ascending order but only order the even numbers and leave all odd numbers in their place.ExampleFollowing is the code − Live ... Read More

Calculating variance for an array of numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:48:38

2K+ Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers sorted in increasing order.Our function should calculate the variance for the array of numbers. Variance of a set of numbers is calculated on the basis of their mean.$Mean (M) = ( \sum_{i=0}^{n-1} arr[i])$ / nAnd ... Read More

Finding the nth power of array element present at nth index using JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:46:31

322 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should map the input array to another array in which each element is raised to its 0-based index.And finally, our function should return this new array.ExampleFollowing is the code − Live Democonst arr = ... Read More

Evaluating a mathematical expression considering Operator Precedence in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:46:11

528 Views

ProblemWe are required to write a JavaScript function that takes in a mathematical expression as a string and return its result as a number.We need to support the following mathematical operators −Division / (as floating-point division)Addition +Subtraction -Multiplication *Operators are always evaluated from left-to-right, and * and / must be ... Read More

Sorting 2-D array of strings and finding the diagonal element using JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:44:33

153 Views

ProblemWe are required to write a JavaScript function that takes in an array of n strings. And each string in the array consists of exactly n characters.Our function should first sort the array in alphabetical order. And then return the string formed by the characters present at the principal diagonal ... Read More

Finding the sum of all common elements within arrays using JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 06:43:56

282 Views

ProblemWe are required to write a JavaScript function that takes in three arrays of numbers. Our function should return the sum of all those numbers that are common in all three arrays.ExampleFollowing is the code − Live Democonst arr1 = [4, 4, 5, 8, 3]; const arr2 = [7, 3, 7, ... Read More

Greatest number divisible by n within a bound in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:50:05

373 Views

ProblemWe are required to write a JavaScript function that takes in a number n and bound number b.Our function should find the largest integer num, such that −num is divisible by divisornum is less than or equal to boundnum is greater than 0.ExampleFollowing is the code − Live Democonst n = ... Read More

Finding the sum of minimum value in each row of a 2-D array using JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:49:45

314 Views

ProblemWe are required to write a JavaScript function that takes in a 2-D array of numbers. Our function should pick the smallest number from each row of the 2-D array and then finally return the sum of those smallest numbers.ExampleFollowing is the code − Live Democonst arr = [    [2, ... Read More

Advertisements