AmitDiwan has Published 10740 Articles

Intersection of three sorted arrays in JavaScript

AmitDiwan

AmitDiwan

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

469 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

189 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

369 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

333 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

516 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

629 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

665 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

200 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

415 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

Picking all elements whose value is equal to index in JavaScript

AmitDiwan

AmitDiwan

Updated on 26-Feb-2021 08:53:51

262 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 then construct and return a new array based on the original array.The new array should contain all those elements from the original array whose value was ... Read More

Advertisements