AmitDiwan has Published 10744 Articles

Finding sort order of string in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Oct-2020 12:33:23

176 Views

We are required to write a JavaScript function that takes in a string and checks whether it is sorted or not.For example:isSorted('adefgjmxz') // true isSorted('zxmfdba') // true isSorted('dsfdsfva') // falseTherefore, let’s write the code for this function −ExampleThe code for this will be −const str = 'abdfhlmxz'; const findDiff = ... Read More

Pushing false objects to bottom in JavaScript

AmitDiwan

AmitDiwan

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

184 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

256 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

135 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

167 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

147 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

223 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

461 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

112 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

127 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

Advertisements