AmitDiwan has Published 10744 Articles

Map anagrams to one another in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 09:57:21

202 Views

Anagram arrays:One array is an anagram of another if we can randomise the elements of that array to achieve the other array.For example −[1, 2, 3] and [2, 1, 3] are anagrams of each other.Suppose, we have two arrays, arr1 and arr2 which are anagrams of each other.We are required ... Read More

Intersection of three sorted arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 09:55:03

440 Views

We are required to write a JavaScript function that takes in three arrays of integers all sorted in an increasing order. The function should then construct and return an array that contains only those elements that present in all three arrays.For example −If the input arrays are −const arr1 = ... Read More

Validating a square in a 2-D plane in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 09:07:59

160 Views

We are required to write a JavaScript function that takes in four arguments. The four arguments will all be arrays of exactly two numbers representing the coordinates of four vertices of a quadrilateral or any figure (closed or unclosed) on a plane.The task of our function is to determine whether ... Read More

Finding maximum number of consecutive 1's in a binary array in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 09:06:08

332 Views

We are required to write a JavaScript function that takes in a binary array (an array that consists of 0 or 1 only) as the only argument.The function should find the length of that consecutive subarray of the array that consists of only 1 and return it.For example −If the ... Read More

Finding minimum steps to make array elements equal in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 09:04:22

303 Views

We are required to write a JavaScript function that takes in a number, num as the only argument. The function should first construct an array of n elements based on the following rule −arr[i] = (2 * i) + 1;Therefore, if the input number is 5, then the array should ... Read More

Finding even length numbers from an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 09:02:29

485 Views

We are required to write a JavaScript function that takes in an array of Integers as the first and the only argument. The function should then construct and return a new array that contains only those elements from the original array that contains an even number of digits.For example −If ... Read More

Finding average of n top marks of each student in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 09:00:58

584 Views

Suppose, we have an array of objects that contains information about some students and the marks scored by them over a period of time like this −const marks = [    { id: 231, score: 34 },    { id: 233, score: 37 },    { id: 231, score: 31 ... Read More

Calculating average of a sliding window in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 08:59:29

621 Views

We are required to write a JavaScript function that takes in an array of integers, arr, as the first argument and a number, num (num < length of arr) as the second argument. The function should construct and return a new array that contains the average of all possible num ... Read More

Checking for uniqueness in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 08:57:54

172 Views

We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument. The function should return true if all the numbers in the array appear only once (i.e., all the numbers are unique), and false otherwise.For example −If the input ... Read More

Finding the largest non-repeating number in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 08:56:04

391 Views

We are required to write a JavaScript function that takes in an array of Integers as the first and the only argument.The function should then iterate through the array and pick that largest number from the array which only appeared once in the array. After that, return this number and ... Read More

Advertisements