AmitDiwan has Published 10744 Articles

Find the middle element of an array using recursion JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:40:06

461 Views

We are required to write an array function, say findMiddle that returns the middlemost element of the array without accessing its length property and without using any kind of built-in loops. If the array contains an odd number of elements, we return the one, middlemost element, or if the array ... Read More

Check whether a series of operations yields a given number with JavaScript Recursion

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:38:07

126 Views

By starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite amount of new numbers can be produced. We are required to write a function that, given a number, tries to find a sequence of such additions and multiplications that produce that number. And ... Read More

Chunking an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:32:50

774 Views

We are required to write a function chunk() that takes in an array arr of string / number literals as the first argument and a number n as second argument.We are required to return an array of n subarrays, each of which contains at most arr.length / n elements. And ... Read More

How do I recursively remove consecutive duplicate elements from an array?

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:15:11

624 Views

Suppose, we have an array of Number literals that contains some consecutive redundant entries like this −const testArr = [1, 1, 2, 2, 3, 3, 1, 1, 1];We are supposed to write a function compress that takes in this array and removes all redundant consecutive entries in place. So that ... Read More

Check if some elements of array are equal JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:13:13

397 Views

We have an array of numbers that have got some redundant entries, our job is to write a function that takes in the array and groups all the identical entries into one subarray and returns the new array thus formed.For example −//If the input array is: const arr = [1, ... Read More

Flatten an array in JavaScript.

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:08:53

309 Views

We are required to write a JavaScript array function that takes in a nested array and returns an array with all the elements present in the array without any nesting.For example −//if the input is: const arr = [[1, 2, 3], [4, 5], [6]]; //then the output should be: const ... Read More

Get minimum number without a Math function JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:06:36

258 Views

We have to write a function that takes in n Number literals as argument, where n is any whole number and returns the smallest number of those numbers without using any library function.We will solve this problem via a while loop and the code for this will be −Exampleconst numbers ... Read More

Counting how many times an item appears in a multidimensional array in JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:05:36

998 Views

We have a nested array of strings and we have to write a function that accepts the array and a search string and returns the count of the number of times that string appears in the nested array.Therefore, let’s write the code for this, we will use recursion here to ... Read More

How can I split an array of Numbers to individual digits in JavaScript?

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:03:37

484 Views

We have an array of Number literals, and we are required to write a function, say splitDigit() that takes in this array and returns an array of Numbers where the numbers greater than 10 are splitted into single digits.For example −//if the input is: const arr = [ 94, 95, ... Read More

Intersection of two arrays JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 07:01:52

649 Views

We have two arrays of Numbers, and we are required to write a function, say intersection() that computes their intersection and returns an array that contains the intersecting elements in any order. Each element in the result should appear as many times as it shows in both arrays.For example − ... Read More

Advertisements