AmitDiwan has Published 10744 Articles

Summing up unique array values in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 11:57:06

154 Views

We are required to write a JavaScript function that takes in an array of numbers that may contain some duplicate numbers. Our function should return the sum of all the unique elements (elements that only appear once in the array) present in the array.For exampleIf the input array is −const ... Read More

Add matching object values in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 11:55:11

363 Views

Suppose, we have an array of objects like this −const arr = [{a: 2, b: 5, c: 6}, {a:3, b: 4, d:1}, {a: 1, d: 2}];Each object is bound to have unique in itself (for it to be a valid object), but two different objects can have the common keys ... Read More

Sorting a JSON object in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 11:53:46

3K+ Views

Suppose we have an object like this −const obj = {    key1: 56,    key2: 67,    key3: 23,    key4: 11,    key5: 88 };We are required to write a JavaScript function that takes in this object and returns a sorted array like this −const arr = [11, ... Read More

Filtering array to contain palindrome elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 11:52:20

313 Views

We are required to write a JavaScript function that takes in an array of String / Number literals and returns a subarray of all the elements that were palindrome in the original array.For exampleIf the input array is −const arr = ['carecar', 1344, 12321, 'did', 'cannot'];Then the output should be ... Read More

Reverse mapping an object in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 12:19:45

1K+ Views

Suppose, we have an object like this −const products = {    "Pineapple":38,    "Apple":110,    "Pear":109 };All the keys are unique in themselves and all the values are unique in themselves.We are required to write a function that accepts a value and returns its key. Let' say we have ... Read More

Expanding Numerals in JavaScript

AmitDiwan

AmitDiwan

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

118 Views

We are required to write a function that, given a number, say, 123, will output an array −[100, 20, 3]Basically, the function is expected to return an array that contains the place value of all the digits present in the number taken as an argument by the function.We can solve ... Read More

Grouping array of array on the basis of elements in JavaScript

AmitDiwan

AmitDiwan

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

210 Views

Suppose, we have an array of arrays of numbers like this −const arr = [[1, 45], [1, 34], [1, 49], [2, 34], [4, 78], [2, 67], [4, 65]];Each subarray is bound to contain strictly two elements. We are required to write a function that constructs a new array where all ... Read More

Constructing 2-D array based on some constraints in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 12:13:21

97 Views

We are required to write a JavaScript function that creates a multi-dimensional array based on some inputs.It should take in three elements, namely −row - the number of subarrays to be present in the array, col - the number of elements in each subarray, val - the val of each ... Read More

Constructing a nested JSON object in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 12:09:56

7K+ Views

We have a special kind of string that contains characters in couple, like this −const str = "AABBCCDDEE";We are required to construct an object based on this string which should look like this −const obj = {    code: "AA",    sub: {       code: "BB",     ... Read More

Removing duplicates and inserting empty strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 12:05:45

293 Views

We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end.For example:If we find 4 duplicate values we have to remove then all and insert four empty strings at the end.Therefore, let’s write the ... Read More

Advertisements