AmitDiwan has Published 10744 Articles

Pair of (adjacent) elements of an array whose sum is lowest JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:41:17

476 Views

We are required to write a JavaScript function that takes in an array of numbers. The function should return a subarray of two adjacent elements from the original array whose sum is the least amongst all adjacent pairs of the array.If the length of the array is less than 2, ... Read More

Subarrays product sum in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:38:03

154 Views

We are required to write a JavaScript function that takes in an array of numbers of length N such that N is a positive even integer and divides the array into two sub arrays (say, left and right) containing N/2 elements each.The function should do the product of the subarrays ... Read More

Sum of all the non-repeating elements of an array JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:35:21

440 Views

Suppose, we have an array of numbers like this −const arr = [14, 54, 23, 14, 24, 33, 44, 54, 77, 87, 77, 14];We are required to write a JavaScript function that takes in one such array and counts the sum of all the elements of the array that appear ... Read More

Checking for Fibonacci numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:31:52

1K+ Views

We are required to write a JavaScript function that takes in a number and checks whether it is a Fibonacci number or not (i.e., it falls in Fibonacci series or not).Our function should return true if the number is a Fibonacci number, false otherwise.The code for this will be −const ... Read More

Finding first unique element in sorted array in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:30:04

175 Views

Suppose, we have a sorted array of literals like this −const arr = [32, 32, 63, 63, 63, 75, 75, 86, 87, 88, 89];We are required to write a JavaScript function that takes in one such array and returns the first unique number in the array.If there is no such ... Read More

Finding smallest number using recursion in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:28:15

190 Views

We are required to write a JavaScript function that takes in an array of Numbers and returns the smallest number from it using recursion.Let’s say the following are our arrays −const arr1 = [-2, -3, -4, -5, -6, -7, -8]; const arr2 = [-2, 5, 3, 0];The code for this ... Read More

JavaScript Get English count number

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:26:21

195 Views

We are required to write a JavaScript function that takes in a number and returns an English count number for it.For example 3 returns 3rdThe code for this will be −const num = 3; const englishCount = num => {    if (num % 10 === 1 && num % 100 ... Read More

How to find capitalized words and add a character before that in a given sentence using JavaScript?

AmitDiwan

AmitDiwan

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

194 Views

Suppose, we have a string that contains some capitalized English alphabets like this −const str = "Connecting to server Connection has been successful We found result";We are required to write a JavaScript function that takes in one such string and inserts a comma ', ' before the space before every ... Read More

Remove smallest number in Array JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:22:01

665 Views

We are required to write a JavaScript function that takes in an array of numbers. The number should find the smallest element in the array and remove it in place.The code for this will be −const arr = [2, 1, 3, 2, 4, 5, 1]; const removeSmallest = arr => ... Read More

Convert number to a reversed array of digits in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Oct-2020 11:20:15

178 Views

Given a non-negative integer, we are required to write a function that returns an array containing a list of independent digits in reverse order.For example:348597 => The correct solution should be [7, 9, 5, 8, 4, 3]The code for this will be −const num = 348597; const reverseArrify = num ... Read More

Advertisements