AmitDiwan has Published 10744 Articles

How to filter out common array in array of arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:25:35

250 Views

Suppose we have an array of arrays like this −const arr = [    [       "Serta",       "Black Friday"    ],    [       "Serta",       "Black Friday"    ],    [       "Simmons",       "Black Friday" ... Read More

Sort an array according to another array in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:22:53

368 Views

Suppose we have two arrays of literals like these −const arr1 = [1, 3, 2, 4, 5, 6]; const arr2 = [1, 2, 5];We are required to write a JavaScript function that takes in two such arrays. Then our function should return a new array that contains all the elements ... Read More

Removing duplicate objects from array in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:20:43

305 Views

Suppose, we have an array of objects like this −const arr = [    {"title": "Assistant"},    {"month": "July"},    {"event": "Holiday"},    {"title": "Assistant"} ];We are required to write a JavaScript function that takes in one such array. Our function should then return a new array that contains all ... Read More

Remove element from array referencing spreaded array in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:18:51

227 Views

Suppose we have an array of literals like this −const arr = ['cat', 'dog', 'elephant', 'lion', 'tiger', 'mouse'];We are required to write a JavaScript function that takes in one such array as the first argument and then any number of strings as second and third and many more arguments.Then our ... Read More

How to merge two strings alternatively in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:17:20

1K+ Views

We are required to write a JavaScript function that takes in two. Our function should then return a new array that contains characters alternatively from both the strings.For example: If the two strings are −const str1 = 'abc'; const str2 = 'def';OutputThen the output should be −const output = 'adbecf';ExampleThe ... Read More

Removing duplicate values in a twodimensional array in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:15:55

1K+ Views

We are required to write a JavaScript function that takes in a two-dimensional array of literals.Our function should return a new array that contains all the entries from the original array but the repeating ones.ExampleThe code for this will be −const arr = [    [1, 2, 3, 4, 5], ... Read More

Retaining array elements greater than cumulative sum using reduce() in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:13:57

150 Views

We are required to write a JavaScript function that takes in an array of Numbers. Our function should return a new array that contains all the elements from the original array that are greater than the cumulative sum of all elements up to that point. We are required to solve ... Read More

Cumulative sum of elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:12:19

1K+ Views

Suppose, we have an array of numbers like this −const arr = [1, 2, 3, 4, 5, 6];We are required to write a JavaScript function that takes in one such array and returns a new array with corresponding elements of the array being the sum of all the elements upto ... Read More

Replace all occurrence of specific words in a sentence based on an array of words in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:10:32

507 Views

We are required to write a JavaScript function that takes a string and an array of strings.Our function should return a new string, where all the occurrences of the word in the string that are present in the array are replaced by a whitespace.Our function should use the String.prototype.replace() method ... Read More

Group strings starting with similar number in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Oct-2020 11:09:03

274 Views

Suppose, we have an array of Numbers represented by strings like this −const arr = ["1.1", "1.2", "1.3", "2.1", "2.2", "3.1", "3.2", "3.3", "4.1", "4.2"];We are required to write a JavaScript function that takes in one such array and groups all the strings starting with same number in a common ... Read More

Advertisements