AmitDiwan has Published 10740 Articles

Pushing false objects to bottom in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:30:28

206 Views

Suppose we have an array of objects like this −const array = [    {key: 'a', value: false},    {key: 'a', value: 100},    {key: 'a', value: null},    {key: 'a', value: 23} ];We are required to write a JavaScript function that takes in one such array and places all ... Read More

Frequency of vowels and consonants in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:27:02

284 Views

We are required to write a JavaScript function that takes in a string which contains English alphabets. The function should return an object containing the count of vowels and consonants in the string.Therefore, let’s write the code for this function −ExampleThe code for this will be −const str = 'This ... Read More

Finding upper elements in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:24:44

157 Views

We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return an array of all the elements from the input array that are greater than or equal to the number ... Read More

Maps in JavaScript takes keys and values array and maps the values to the corresponding keys

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:22:55

193 Views

Suppose we have two arrays −const keys = [0, 4, 2, 3, 1]; const values = ["first", "second", "third", "fourth", "fifth"];We are required to write a JavaScript function that takes in the keys and the values array and maps the values to the corresponding keys.Therefore, the output should look like ... Read More

Function to choose elements randomly in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:15:08

167 Views

Suppose we have an array of literals that contains no duplicate elements like this −const arr = [2, 5, 4, 45, 32, 46, 78, 87, 98, 56, 23, 12];We are required to write a JavaScript function that takes in an array of unique literals and a number n. The function ... Read More

Sort the second array according to the elements of the first array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:04:17

261 Views

Suppose, we have two arrays like these −const arr1 = ['d', 'a', 'b', 'c'] ; const arr2 = [{a:1}, {c:3}, {d:4}, {b:2}];We are required to write a JavaScript function that accepts these two arrays. The function should sort the second array according to the elements of the first array.We have ... Read More

Absolute difference of Number arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:02:46

480 Views

Suppose, we have two arrays like these −const arr1 = [1, 2, 3, 4, 5, 6]; const arr2 = [9, 8, 7, 5, 8, 3];We are required to write a JavaScript function that takes in such two arrays and returns an array of absolute difference between the corresponding elements of ... Read More

Outputting a random number that falls in a certain range in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:00:13

141 Views

We are required to write a JavaScript function that takes in a number, say n, and an array of two numbers that represents a range. The function should return an array of n random elements all lying between the range provided by the second argument.Therefore, let’s write the code for ... Read More

Constructing an object from repetitive numeral string in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 11:58:45

149 Views

Suppose, we have a string with digits like this −const str = '11222233344444445666';We are required to write a JavaScript function that takes in this string and returns an object that represents the count of each number in the string.So, for this string, the output should be −const output = { ... Read More

Summing up unique array values in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 11:57:06

180 Views

We are required to write a JavaScript function that takes in an array of numbers that may contain some duplicate numbers. Our function should return the sum of all the unique elements (elements that only appear once in the array) present in the array.For exampleIf the input array is −const ... Read More

Advertisements