AmitDiwan has Published 10740 Articles

Convert array of arrays to array of objects grouped together JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:59:09

1K+ Views

Let’s say, we have a two-dimensional array that contains data about some colors and fruits like thisconst data = [    ['orange', 'fruit'],    ['red', 'color'],    ['green', 'color'],    ['orange', 'color'],    ['banana', 'fruit'],    ['blue', 'color'],    ['lemon', 'fruit'],    ['mango', 'fruit'],    ['lemon', 'color'], ];We have to ... Read More

Convert 2D array to object using map or reduce in JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:56:41

1K+ Views

Let’s say, we have a two-dimensional array that contains some data about the age of some people.The data is given by the following 2D arrayconst data = [    ['Rahul', 23],    ['Vikky', 27],    ['Sanjay', 29],    ['Jay', 19],    ['Dinesh', 21],    ['Sandeep', 45],    ['Umesh', 32],   ... Read More

How to multiply odd index values JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:52:37

402 Views

We are required to write a function, that takes in an array of Number literals as one and the only argument. The numbers that are situated at even index should be returned as it is. But the numbers situated at the odd index should be returned multiplied by their corresponding ... Read More

Find char combination in array of strings JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:51:37

161 Views

We have to write a function that accepts an array of strings and a string. Our job is to check whether the array contains any sequence or subsequence of the string as its element or not, and the function should return a boolean based on this fact.For instance −const x ... Read More

Calculating least common of a range JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:49:34

164 Views

We are required to write a function that takes in an array of two numbers a and b (a >= b) and returns the least common multiple of all the numbers between [a, b].ApproachWe will first write a basic function that calculates the least common multiple of two numbers, once ... Read More

Write a program to calculate the least common multiple of two numbers JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:46:45

884 Views

We are required to write a function that accepts two numbers and returns their least common multiple.Least Common Multiple (LCM)The least common multiple of two numbers a and b is the smallest positive integer that is divisible by both a and b.For example − The LCM of 6 and 8 ... Read More

map() array of object titles into a new array based on other property value JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:44:54

263 Views

Let’s say, we have an array of objects like this −const arr = [{    country: "cananda",    count: 2 }, {       country: "jamaica",       count: 2 }, {       country: "russia",       count: 1 }, {       country: ... Read More

Construct string via recursion JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:41:33

351 Views

We are required to write a recursive function, say pickString that takes in a string that contains a combination of alphabets and numbers and returns a new string consisting of only alphabets.For example, If the string is ‘dis122344as65t34er’, The output will be: ‘disaster’Therefore, let’s write the code for this recursive ... Read More

Find and return array positions of multiple values JavaScript

AmitDiwan

AmitDiwan

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

4K+ Views

We have to write a function, say findPositions() that takes in two arrays as argument. And it should return an array of the indices of all the elements of the second array present in the first array.For example −If the first array is [‘john’, ‘doe’, ‘chris’, ‘snow’, ‘john’, ‘chris’], And ... Read More

How can I remove a specific item from an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 25-Aug-2020 06:38:31

291 Views

We are required to write a function for arrays Array.prototype.remove(). It accepts one argument; it is either a callback function or a possible element of the array. If it’s a function then the return value of that function should be considered as the possible element of the array and we ... Read More

Advertisements