AmitDiwan has Published 10744 Articles

Counting number of vowels in a string with JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:57:09

669 Views

We are required to write a JavaScript function that takes in a string. The function should count the number of vowels present in the string.The function should prepare an object mapping the count of each vowel against them.ExampleThe code for this will be −const str = 'this is an example ... Read More

Return a sorted array in lexicographical order in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:56:02

400 Views

We are required to write a JavaScript function that takes two arrays, say arr1 and arr2. Our function should return a sorted array in lexicographical order of the strings of arr1 which are substrings of strings of arr2.ExampleThe code for this will be −const lexicographicalSort = (arr1 = [], arr2 ... Read More

Find all substrings combinations within arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:54:20

369 Views

We are required to write a JavaScript function that takes in an array of strings. The function should find all the substring and superstring combinations that exist in the array and return an array of those elements.For example − If the array is −const arr = ["abc", "abcd", "abcde", "xyz"];Then ... Read More

Highest occurrence in an array or first selected in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:52:07

149 Views

We are required to write a JavaScript function that takes in an array of literal values. Our function should then return the highest occurrence of an array value, and if there's an equal occurrence, we should return the first selected value of the equal occurrences.const arr = ['25', '50', 'a', ... Read More

Counting number of words in a sentence in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:50:56

538 Views

We are required to write a JavaScript function that takes in a string. Our function is supposed to count the number of alphabets (uppercase or lowercase) in the array.For example − If the input string is −const str = 'this is a string!';Then the output should be −13ExampleThe code for ... Read More

Sort an array of objects by multiple properties in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:49:23

1K+ Views

Suppose, we have an array of objects like this −const arr = [    { id: 1, score: 1, isCut: false, dnf: false },    { id: 2, score: 2, isCut: false, dnf: false },    { id: 3, score: 3, isCut: false, dnf: false },    { id: 4, ... Read More

How to convert nested array pairs to objects in an array in JavaScript ?

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:47:23

1K+ Views

Suppose, we have an array of arrays like this −const arr = [    [       ['firstName', 'Joe'],       ['lastName', 'Blow'],       ['age', 42],       ['role', 'clerk'],       [          ['firstName', 'Mary'],          ['lastName', ... Read More

How to check if an array contains integer values in JavaScript ?

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 09:45:17

1K+ Views

We are required to write a JavaScript function that takes in an array of elements.Our function should check whether or not the array contains an integer value.We should return true if it does false otherwise.ExampleThe code for this will be −const arr = ["123", "", "21345", "90"]; const findInteger = ... Read More

Split number into 4 random numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 07:02:12

877 Views

We are required to write a JavaScript function that takes in a number as the first input and a maximum number as the second input.The function should generate four random numbers, which when summed should equal the number provided to function as the first input and neither of those four ... Read More

How to build a string with no repeating character n separate list of characters? in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Nov-2020 07:00:33

407 Views

Suppose, we n separate array of single characters. We are required to write a JavaScript function that takes in all those arrays.The function should build all such possible strings that −contains exactly one letter from each arraymust not contain any repeating character (as the arrays might contain common elements)For the ... Read More

Advertisements