AmitDiwan has Published 10744 Articles

Reshaping 2-D array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 12:28:45

979 Views

ProblemWe are required to write a JavaScript function that takes in a 2-D array of numbers, arr, as the first argument and two numbers, r and c, representing the row number and column number of the desired matrix, respectively.Our function should form and return a new 2-D array with the specified rows ... Read More

Length of shortest unsorted array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 12:20:05

164 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.Our function needs to find the length of one continuous subarray such that if we only sort this subarray in ascending order, then the whole array will be ... Read More

Longest subarray with unit difference in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 12:17:48

103 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argumentOur function should find and return the length of such a subarray where the difference between its maximum value and its minimum value is exactly 1.For example, if ... Read More

Merging nested arrays to form 1-d array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 12:08:05

322 Views

ProblemWe are required to write a JavaScript function that takes in two nested arrays, arr1 and arr2, as the first and the second argument.Our function should create and return a third array that contains all the elements of arr1 and arr2 but flattened to single dimensionFor example, if the input ... Read More

Filtering out numerals from string in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 12:02:33

166 Views

ProblemWe are required to write a JavaScript function that takes in a string, str, which contains a combination of alphabets, special characters and numbers.Our function should return a new string based on the input string that contains only the numbers present in the string str, maintaining their relative order.For example, ... Read More

Decreasing order sort of alphabets in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 11:56:19

178 Views

ProblemWe are required to write a JavaScript function that takes in a lowercase English alphabets string, str, as the first and the only argumentOur function should create and return a new string based on the input string which contains characters sorted according to the reverse English alphabets.For example, if the ... Read More

Merging and rectifying arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 11:50:24

133 Views

ProblemWe are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, as the first and the second arguments.Our function should merge the elements of both these arrays into a new array and if upon merging or before merging there exists any duplicates, we ... Read More

Accumulating array elements to form new array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 10:32:48

232 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a number, num, (num {    const res = [];    let sum = 0, right = 0, left = 0;    for(; right < num; right++){   ... Read More

Common element with least index sum in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 10:26:29

171 Views

ProblemWe are required to write a JavaScript function that takes in two arrays of literals, arr1 and arr2, as the first and the second argument.Our function should find out the common element in arr1 and arr2 with the least list index sum. If there is a choice tie between answers, ... Read More

Difference Between Website and Blog

AmitDiwan

AmitDiwan

Updated on 21-Apr-2021 07:38:21

277 Views

In this post, we will understand the difference between a website and a blog −WebsiteIt is a collection of webpages and multimedia content.This is made available under one domain on the World Wide Web.The websites are usually hosted using a web hosting service.This allows the web pages and the content ... Read More

Advertisements