AmitDiwan has Published 10744 Articles

JavaScript - Find the smallest n digit number or greater

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:18:58

388 Views

We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n digit number which is a multiple of all the elements specified in the array. If ... Read More

Find the Sum of fractions - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:16:53

681 Views

We have an array of arrays like this −const arr = [[12, 56], [3, 45], [23, 2], [2, 6], [2, 8]];Note that while the array can have any number of elements, each subarray should strictly contain two numbers.The two numbers in each subarray represents a fraction. For example, the fraction ... Read More

Digit distance of two numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:15:44

334 Views

We are required to write a JavaScript function that takes in two numbers a and b returns their digit distance.Digit distanceThe digit distance of two numbers is the absolute sum of the difference between their corresponding digits.For example: If the numbers are −345 678Then the digit distance will be −|3-6| ... Read More

Sum of prime numbers between a range - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:14:44

513 Views

We are required to write a JavaScript function that takes in two numbers, say a and b and returns the sum of all the prime numbers that fall between a and b. We should include a and b if they are prime as well.ExampleFollowing is the code −const num1 = ... Read More

Finding unique string in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:12:05

414 Views

Suppose, we have the following array of strings that might contain duplicate characters −const arr = ['54gdgdfe3', '434ffd', '43frdf', '43fdhnh', 'wgcxhjny', 'fsdf34'];We are required to write a JavaScript function that takes in one such array and returns the very first element from the array that contains 0 duplicate characters.If there ... Read More

Odd even sort in an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:10:43

1K+ Views

We are required to write a JavaScript function that takes in an array of numbers and sorts the array such that first all the even numbers appear in ascending order and then all the odd numbers appear in ascending order.For example: If the input array is −const arr = [2, ... Read More

Finding missing letter in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:09:15

688 Views

We have a string of length m that contains first m letters of the English alphabets, but somehow, one element went missing from the string. So, now the string contains, m-1 lettersWe are required to write a function that takes in one such string and returns the missing element from ... Read More

Repeating letter string - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:07:56

1K+ Views

We are required to write a JavaScript function that takes in a string and a number, say n, and the function should return a new string in which all the letters of the original string are repeated n times.For example: If the string is −const str = 'how are you'And ... Read More

Change every letter to next letter - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:06:46

726 Views

We are required to write a JavaScript function that takes in a string and changes every letter of the string from the English alphabets to its succeeding element.For example: If the string is −const str = 'how are you';Then the output should be −const output = 'ipx bsf zpv'ExampleFollowing is ... Read More

Absolute sum of array elements - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:05:34

798 Views

We are required to write a JavaScript function that takes in an array with both positive and negative numbers and returns the absolute sum of all the elements of the array.We are required to do this without taking help of any inbuilt library function.For example: If the array is −const ... Read More

Advertisements