AmitDiwan has Published 8358 Articles

Generate Ranking with combination of strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:10:15

320 Views

We are required to write a JavaScript function that takes in any number of arrays of numbers. Then the function should return an object that returns a frequency map indicating how many times each element has appeared checking in all the array.For example, If the arrays are −const a = ... Read More

How to iterate over objects in array and sum a property in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:07:14

895 Views

Suppose we have an array of objects like this −const arr = [    {       duration: 10,       any: 'fields'    }, {       duration: 20,       any: 'other fields'    }, {       duration: 15,       ... Read More

Grouping names based on first letter in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:04:54

1K+ Views

Suppose, we have an array of names like this −const arr = ["Simon", "Mike", "Jake", "Lara", "Susi", "Blake", "James"];We are required to write a JavaScript function that takes in one such array. The function should return an array of objects with two properties −letter -> the letter on which the ... Read More

How to convert array into array of objects using map() and reduce() in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:54:46

991 Views

Suppose we have an array of arrays like this −const arr = [    [       ['juice', 'apple'], ['maker', 'motts'], ['price', 12]    ],    [       ['juice', 'orange'], ['maker', 'sunkist'], ['price', 11]    ] ];We are required to write a JavaScript function that takes in ... Read More

How to convert array of decimal strings to array of integer strings without decimal in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:52:49

734 Views

We are required to write a JavaScript function that takes in an array of decimal strings. The function should return an array of strings of integers obtained by flooring the original corresponding decimal values of the array.For example, If the input array is −const input = ["1.00", "-2.5", "5.33333", "8.984563"];Then ... Read More

Group by element in array JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:50:13

467 Views

Suppose, we have an array of objects like this −const arr = [    {"name": "toto", "uuid": 1111},    {"name": "tata", "uuid": 2222},    {"name": "titi", "uuid": 1111} ];We are required to write a JavaScript function that splits the objects into separate array of arrays that have the similar values ... Read More

Find array elements that are out of order in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:48:25

305 Views

Suppose we have an array of sorted numbers but some elements of the array are out of their sorted order.We are required to write a JavaScript function that takes in one such array and returns a subarray of all those elements that are out of order.ExampleThe code for this will ... Read More

Return the index of first character that appears twice in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:44:27

327 Views

We are required to write a JavaScript function that takes in a string and returns the index of first character that appears twice in the string.If there is no such character then we should return -1.ExampleThe code for this will be −const str = 'Hello world, how are you'; const ... Read More

Sum of distinct elements of an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:40:28

256 Views

Suppose, we have an array of numbers like this −const arr = [1, 5, 2, 1, 2, 3, 4, 5, 7, 8, 7, 1];We are required to write a JavaScript function that takes in one such array and counts the sum of all distinct elements of the array.For example:The output ... Read More

Finding the first unique element in a sorted array in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:35:48

592 Views

Suppose we have a sorted array of literals like this −const arr = [2, 2, 3, 3, 3, 5, 5, 6, 7, 8, 9];We are required to write a JavaScript function that takes in one such array and returns the first number that appears only once in the array.If there ... Read More

Advertisements