AmitDiwan has Published 10740 Articles

Subset with maximum sum in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 06:55:04

354 Views

We are required to write a JavaScript function that takes in an array of integers. Our function is required find the subset of non−adjacent elements with the maximum sum.And finally, the function should calculate and return the sum of that subset.For example −If the input array is −const arr = ... Read More

Are the strings anagrams in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 06:51:07

197 Views

Anagrams −Two strings are said to be anagrams of each other if by rearranging, rephrasing or shuffling the first we can form a string identical to the second.For example −'something' and 'emosghtin' are anagrams of each other.We are required to write a JavaScript function that takes in two string, say ... Read More

Find what numbers were pressed to get the word (opposite of phone number digit problem) in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 06:49:38

184 Views

The mapping of the numerals to alphabets in the old keypad type phones used to be like this −const mapping = {    1: [],    2: ['a', 'b', 'c'],    3: ['d', 'e', 'f'],    4: ['g', 'h', 'i'],    5: ['j', 'k', 'l'],    6: ['m', 'n', 'o'], ... Read More

Finding product of an array using recursion in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 06:48:32

657 Views

We are required to write a JavaScript function that takes in an array of Integers. Our function should do the following two things −Make use of a recursive approach.Calculate the product of all the elements in the array.And finally, it should return the product.For example −If the input array is ... Read More

Checking the validity of parentheses in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 06:47:13

2K+ Views

We are required to write a JavaScript function that takes in a string str containing just the characters −'(', ')', '{', '}', '[' and ']'Our function should determine if the input string is valid.An input string is valid if −Open brackets must be closed by the same type of brackets.Open ... Read More

Finding the longest "uncommon" sequence in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 06:45:16

181 Views

We are required to write a JavaScript function that takes in an array of strings. The function should find the longest uncommon subsequence among the strings of the array.By longest uncommon subsequence we mean the longest subsequence of one of these strings and this subsequence should not be any subsequence ... Read More

Difference between first and the second array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:29:27

210 Views

We are required to write a JavaScript function that takes in two arrays of literals. The arrays might contain some identical entries as well.The purpose of our function is to simply find out and return an array of all such elements that exists in the first array but not in ... Read More

Find the closest index to given value in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:28:24

439 Views

We are required to write a JavaScript function that takes in an array of numbers as the first input and a single number as the second input.The function should find and return the index of the number from the array which is closest to the number specified by second argument.ExampleThe ... Read More

Using a recursive function to capitalize each word in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:27:17

437 Views

We are required to write a JavaScript function that takes in an array of String literals. The function should do the following two things −Make use of recursive approachMake first word of each string element capital.Our function should do this without using extra space for storing another array.For example −If ... Read More

How to store two arrays as a keyvalue pair in one object in JavaScript?

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:26:07

752 Views

Suppose, we have two arrays of literals of same length like these −const arr1 = ['firstName', 'lastName', 'age', 'address', 'isEmployed']; const arr2 = ['Rahul', 'Sharma', 23, 'Tilak Nagar', false];We are required to write a JavaScript function that takes in two such arrays.The function should construct an object mapping the elements ... Read More

Advertisements