AmitDiwan has Published 10744 Articles

Merge JSON array date based JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:16:25

718 Views

Suppose, we have the following array of objects −const arr = [    {       "date" : "2010-01-01",       "price" : 30    },    {       "date" : "2010-02-01",       "price" : 40    },    {       "date" ... Read More

Merge JavaScript objects with the same key value and count them

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:13:05

4K+ Views

Suppose, we have an array of objects like this −const arr = [{    "value": 10,    "id": "111",    "name": "BlackCat", }, {    "value": 10,    "id": "111",    "name":    "BlackCat", }, {    "value": 15,    "id": "777",    "name": "WhiteCat", }];We are required to write ... Read More

Is the second string a rotated version of the first string JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:11:27

160 Views

We are required to write a JavaScript function that takes in two strings, say str1 and str2. We are required to determine whether or not the second string is a rotated version of the first string.For example− If the input strings are −const str1 = 'abcde'; const str2 = 'cdeab';Then ... Read More

Implementing binary search in JavaScript to return the index if the searched number exist

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:09:41

650 Views

We are required to write a JavaScript function that takes in a sorted array of numbers as the first argument and a search number as the second argument.If the search number exists in the array, we need to return its index in the array, otherwise we need to return -1.We ... Read More

Reversing words within a string JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:08:24

403 Views

We are required to write a JavaScript function that takes in a string that might contain spaces. Our function should first split the string based on the spaces and then reverse and join and return the new string.For example − If the input string is −const str = 'this is ... Read More

Is uppercase used correctly JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:06:58

65 Views

For the purpose of this very problem, we define the correct use of uppercase letter by the following rules −All letters in a word are capitals, like "INDIA".All letters in a word are not capitals, like "example".Only the first letter in a word is capital, like "Ramesh".We are required to ... Read More

Go through an array and sum only numbers JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:04:59

391 Views

We are required to write a JavaScript function that takes in an array. The array might contain any type of value, Number literals, string literals, objects, undefined.Our function should pick all the Number type values and return their sumExampleconst arr = [1, 2, 'a', 4]; const countNumbers = (arr = ... Read More

Sort in multi-dimensional arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:03:57

744 Views

Suppose, we have the following array of arrays −const arr = [ ["A", "F", "A", "H", "F", "F"],  ["F", "A", "A", "F", "F", "H"] ];We are required to write a JavaScript function that takes in one such array.The function should sort all the subarrays of the given array internally according ... Read More

Finding perfect numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 06:02:18

2K+ Views

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.For example −28 is a perfect number, because 28 = 1 + 2 + 4 + ... Read More

Shifting certain elements to the end of array JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 05:58:26

357 Views

We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument.Our function should check for all the instances of second number in the array, if there exists any, the function should push all those ... Read More

Advertisements