ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should construct an output array based on the input array.For each corresponding element our output array should contain the count of number smaller than that number to its right. Finally, we should return ... Read More
ProblemWe are required to write a JavaScript function that takes in a lowercase English alphabet character. Our function should return the character’s 1-based index in the alphabets.ExampleFollowing is the code − Live Democonst char = 'j'; const findCharIndex = (char = '') => { const legend = ' abcdefghijklmnopqrstuvwxyz'; ... Read More
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.The task of our function is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of ... Read More
ProblemWe are required to write a JavaScript function that lives on the prototype Object of the Array class.Our function should take in a callback function as the only argument. This callback function should be called for each element of the array.And that callback function should take in two arguments the ... Read More
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
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
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
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
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
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