AmitDiwan has Published 10744 Articles

Squared concatenation of a Number in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Oct-2020 12:57:07

246 Views

We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenated.For example: If the number is −99Then the output should be −8181because 9^2 is 81 and 1^2 is 1.Therefore, let’s ... Read More

Repeated sum of Number’s digits in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Oct-2020 12:54:30

348 Views

We are required to write a JavaScript function that recursively sums up the digits of a number until it reduces to a single digit number.We are required to do so without converting the number to String or any other data type.Therefore, let’s write the code for this function −ExampleThe code ... Read More

Taking common elements from many arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Oct-2020 12:50:49

522 Views

We are required to write a JavaScript function that takes in any arbitrary number of arrays and returns an array of elements that are common to all arrays. If there are no common elements, then we should return an empty array.Therefore, let’s write the code for this function −ExampleThe code ... Read More

Summing up digits and finding nearest prime in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Oct-2020 12:49:13

111 Views

We are required to write a JavaScript function that takes in a number, finds the sum of its digits and returns a prime number that is just greater than or equal to the sum.Therefore, let’s write the code for this function −ExampleThe code for this will be −const num = ... Read More

Find the Smallest element from a string array in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Oct-2020 12:46:07

295 Views

We are required to write a JavaScript function that takes in an array of strings and returns the index of string that is shortest in length.We will simply use a for loop and persist the index of string which is shortest in length.Therefore, let’s write the code for this function ... Read More

Adding up identical elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:42:29

99 Views

We are required to write a JavaScript function that takes in an array of Numbers and sums all the identical numbers together at one index.For exampleIf the input array is −const arr = [20, 10, 15, 20, 15, 10];Then the output should be −const output = [40, 20, 30];Therefore, let’s ... Read More

Merging two arrays in a unique way in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:41:09

146 Views

We are required to write a JavaScript function that takes in two arrays and merges the arrays taking elements alternatively from the arrays.For exampleIf the two arrays are −const arr1 = [4, 3, 2, 5, 6, 8, 9]; const arr2 = [2, 1, 6, 8, 9, 4, 3];Then the output ... Read More

Picking out uniques from an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:37:34

128 Views

Suppose we have an array that contains duplicate elements like this −const arr = [1, 1, 2, 2, 3, 4, 4, 5];We are required to write a JavaScript function that takes in one such array and returns a new array. The array should only contain the elements that only appear ... Read More

Non-composite numbers sum in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:36:18

158 Views

We are required to write a JavaScript function that takes in an array of numbers.The function should return the sum of all the prime numbers present in the array.Therefore, let’s write the code for this function −ExampleThe code for this will be −const arr = [43, 6, 6, 5, 54, ... Read More

Inverting slashes in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:34:40

337 Views

We are required to write a JavaScript function that takes in a string that may contain some backward slashes.And the function should return a new string where all the backslashes with forward slashes.Therefore, let’s write the code for this function −ExampleThe code for this will be −const str = 'Th/s ... Read More

Advertisements