AmitDiwan has Published 10744 Articles

Calculating quarterly and yearly average through JavaScript

AmitDiwan

AmitDiwan

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

251 Views

Suppose, we have an array of Numbers like this −const arr = [1, 2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];We are required to write a JavaScript function that takes in one such array and chunks the array into ... Read More

Map numbers to characters in JavaScript

AmitDiwan

AmitDiwan

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

1K+ Views

Suppose we have the number 12145. We are required to write a function that maps the digits of the number to English alphabets according to the following norms. The alphabets are to be mapped according to the 1 based index, like 'a' for 1 and 'b' for 2 'c' for ... Read More

Finding shortest word in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:23:40

800 Views

We are required to write a JavaScript function that takes in a string and returns the shortest word from the string.For example: If the input string is −const str = 'This is a sample string';Then the output should be −const output = 'a';ExampleThe code for this will be −const str ... Read More

Dynamic Programming: return all matched data in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:21:59

312 Views

Suppose we have a JSON object that have information about the location of some cities of some countries like this −const countryInfo = {    country: [{       name: "Bangladesh",       province: [{          name:"Dhaka",          city: [{     ... Read More

Get values that are not present in another array in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:16:21

2K+ Views

We are given two arrays: (arr1 and arr2) −arr1 contains some literal values.arr2 contains objects that map some literal values.We are required to write a JavaScript function that takes in two such arrays. Then the function should return an array of all the elements from arr1 that are not mapped ... Read More

All combinations of sums for array in JavaScript

AmitDiwan

AmitDiwan

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

866 Views

We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a number, say n as the second argument. The number n will always be less than or equal to the length of the array.Our function should return an array of ... Read More

Generate Ranking with combination of strings in JavaScript

AmitDiwan

AmitDiwan

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

285 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

863 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

Filtering out only null values in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:02:46

381 Views

We are required to write a JavaScript function that takes in an array that contains some false values. The function should remove all the null values from the array (if there are any) in place.For example: If the input array is −const arr = [12, 5, undefined, null, 0, false, ... Read More

Advertisements