AmitDiwan has Published 10744 Articles

Listing all the prime numbers upto a specific number in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:41:38

201 Views

We are required to write a JavaScript function that takes in a number, say n, and returns an array containing all the prime numbers upto n.For example: If the number n is 24.Then the output should be −const output = [2, 3, 5, 7, 11, 13, 17, 19, 23];Therefore, let’s ... Read More

AND product of arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:40:10

137 Views

We have an array of arrays of boolean like this −const arr = [[true, false, false], [false, false, false], [false, false, true]];We are required to write a function that merges this array of arrays into a one-dimensional array by combining the corresponding elements of each subarray using the AND (&&) ... Read More

Deviations in two JavaScript arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:38:52

170 Views

We have two arrays of numbers like these −const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34];We are required to write a JavaScript function that takes in two such arrays and returns the element from arrays that are ... Read More

Upper or lower elements count in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:37:33

116 Views

Consider we have an array of Numbers that looks like this −const array = [54, 54, 65, 73, 43, 78, 54, 54, 76, 3, 23, 78];We are required to write a function that counts how many of the elements are in the array below / above a given number.For example, ... Read More

Finding sum of all unique elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:33:55

192 Views

We are required to write a JavaScript function that takes in an array of numbers with duplicate entries and sums all the duplicate entries to one index.For example: If the input array is −const input = [1, 3, 1, 3, 5, 7, 5, 4];OutputThen the output should be −const output ... Read More

Similarities between different strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:56:30

126 Views

We have two arrays of Numbers, and we are required to write a function intersection() that computes their intersection and returns an array that contains the intersecting elements in any order. Each element in the result should appear as many times as it shows in both arrays.For example:If input is ... Read More

Grouping of same kind of numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:53:57

170 Views

We have an array of numbers like this −const arr = [-1, -2, -1, 0, -1, -2, -1, -2, -1, 0, 1, 0];We are required to write a JavaScript function that counts the consecutive groups of nonnegative (positives and 0) numbers in the array.Like here we have consecutive non negatives ... Read More

Finding pandigital numbers using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:49:16

187 Views

We are required to write a JavaScript function that takes in a string representing a number. The function returns true if the number is pandigital, false otherwise.A pandigital number is a number that contains all digits (0-9) at least once.Therefore, let’s write the code for this function −ExampleThe code for ... Read More

Twice join of two strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:47:42

149 Views

We are required to write a JavaScript function that takes in two strings; creates and returns a new string with first 2 words of first string, next two words of second string, then first, then second and so on.For example: If the strings are −const str1 = 'Hello world'; const ... Read More

Finding the second most frequent character in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:45:37

283 Views

We are required to write a JavaScript function that takes in a string and returns the character which makes second most appearances in the string.Therefore, let’s write the code for this function −ExampleThe code for this will be −const str = 'Hello world, I have never seen such a beautiful ... Read More

Advertisements