AmitDiwan has Published 10740 Articles

How to reverse a portion of an array in JavaScript?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:19:54

349 Views

We are required to write a JavaScript function that takes in an array, a start index and an end index. The function should reverse the portion of the array between the start index and end index.For example −If the array is −const arr = [2, 6, 5, 8, 3, 5, ... Read More

Find the Symmetric difference between two arrays - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:18:44

280 Views

In Mathematics, the symmetric difference of two sets, say A and B is represented by A △ BAnd it is defined as the set of all those elements which belongs either to A or to B but not to both.For example −const A = [1, 2, 3, 4, 5, 6, ... Read More

Recursion - Sum Nested Array in JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:17:37

982 Views

We are required to write a JavaScript function that takes in a nested array of Numbers and returns the sum of all the numbers present in the array.Let’s say the following is our nested array −const arr = [2, 5, 7, [    4, 5, 4, 7, [     ... Read More

Checking whether the sum of digits of a number forms a Palindrome Number or not in JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:16:06

150 Views

We are required to write a JavaScript function that takes in a number, sums its digits and checks whether that sum is a Palindrome number or not. The function should return true if the sum is Palindrome, false otherwise.For example, if the number is 697, Then the sum of its ... Read More

Swap certain element from end and start of array - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:15:05

232 Views

We are required to write a JavaScript function that accepts an array of Numbers and a number, say n (n must be less than or equal to the length of array). And our function should replace the kth element from the beginning with the nth element from the end of ... Read More

Splitting string into groups – JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:13:58

418 Views

Given a string S, consisting of alphabets, numbers and special characters. We need to write a program to split the strings in three different strings S1, S2 and S3, such that −The string S1 will contain all the alphabets present in S, The string S2 will contain all the numbers ... Read More

Split keys and values into separate objects - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:12:33

4K+ Views

Suppose, we have an object like this −const dataset = {    "diamonds":77,    "gold-bars":28,    "exciting-stuff":52,    "oil":51,    "sports-cars":7,    "bitcoins":40 };We are required to write a JavaScript function that takes one such object and returns an array of objects that have keys and their values splitted.Therefore, for ... Read More

Second most frequent character in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:11:15

816 Views

We are required to write a JavaScript function that takes in a string and returns the character from the string that appears for second most number of times.Let’s say the following is our string −const str = 'This string will be used to calculate frequency';Above, the second most frequent character ... Read More

Deleting the duplicate strings based on the ending characters - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:10:02

200 Views

We are required to write a JavaScript function that takes in an array of strings and deletes each one of the two strings that ends with the same character −For example, If the actual array is −const arr = ['Radar', 'Cat' , 'Dog', 'Car', 'Hat'];Then we have to delete one ... Read More

Calculating excluded average - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:08:52

185 Views

Suppose we have an array of objects like this −const arr = [    {val: 56, canUse: true},    {val: 16, canUse: true},    {val: 45, canUse: true},    {val: 76, canUse: false},    {val: 45, canUse: true},    {val: 23, canUse: false},    {val: 23, canUse: false},    {val: ... Read More

Advertisements