AmitDiwan has Published 10744 Articles

Greatest number in a dynamically typed array in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 12:08:49

142 Views

We are required to write a JavaScript function that takes in an array that contains some numbers, some strings and some false values. Our function should return the biggest Number from the array.For example: If the input array is −const arr = [23, 'hello', undefined, null, 21, 65, NaN, 1, ... Read More

Finding middlemost element(s) in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 12:07:14

88 Views

We are required to write a JavaScript function that takes in an array of Numbers. The function should return the middlemost element of the array.For example: If the array is −const arr = [1, 2, 3, 4, 5, 6, 7];Then the output should be 4.ExampleThe code for this will be ... Read More

Chunking arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 12:05:57

159 Views

We are required to write a JavaScript function that takes in an array of literals and returns a new array that have elements of the original array chunked into subarrays of length exactly 2. Now if the length of original array is not exactly divisible by 2, then the last ... Read More

Remove leading zeros in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 12:04:32

444 Views

The requirements for this question are simple. We are required to write a JavaScript function that takes in an array of Numbers.If the array contains leading zero, the function should remove the leading zeros in place, otherwise the function should do nothing.For example: If the input array is −const arr ... Read More

Push specific elements to last in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 12:02:58

134 Views

Suppose we have an array of objects like this −const arr = [    {flag: true, other: 1},    {flag: true, other: 2},    {flag: false, other: 3},    {flag: true, other: 4},    {flag: true, other: 5},    {flag: true, other: 6},    {flag: false, other: 7} ];We are ... Read More

Finding the balance of brackets in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 11:58:53

346 Views

Given a string that consists of only two types of characters: "(" and ")". We are required to write a function that takes in one such string and balances the parentheses by inserting either a "(" or a ")" as many times as necessary. The function should then return the ... Read More

Is element repeated more than n times in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 11:56:59

169 Views

We are required to write a JavaScript function that takes in two arguments −An Array, say arr, of literals that may contain some repeating elements.A number, say limit.The function should validate that no element of the array is repeated more than limit number of times. If any element is repeated ... Read More

Writing table of number in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 11:55:22

137 Views

We are required to write a JavaScript function that takes in two numbers, say m and n, and it returns an array of first n multiples of m.Therefore, let’s write the code for this function −ExampleThe code for this will be −const num1 = 4; const num2 = 6; const ... Read More

Counting smaller and greater in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 11:54:09

350 Views

Suppose, we have an array of literals like this −const arr = [3, 5, 5, 2, 23, 4, 7, 8, 8, 9];We are required to write a JavaScript function that takes in this array and a number, say n, and returns an object representing the count of elements greater than ... Read More

Counting unique elements in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Oct-2020 11:52:26

2K+ Views

We are required to write a JavaScript function that counts all unique items in an array. The function should return an object representing the count of each unique element of the array.Therefore, let’s write the code for this function −ExampleThe code for this will be −const arr = ["hi", "hello", ... Read More

Advertisements