
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

674 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 string'; const vowelCount = (str = '') => { const splitString=str.split(''); const obj={}; const vowels="aeiou"; splitString.forEach((letter)=>{ if(vowels.indexOf(letter.toLowerCase()) !== -1){ if(letter in obj){ obj[letter]++; }else{ ... Read More

402 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 = []) => { let i, j; const res = []; outer: for (j = 0; j < arr1.length; j++) { for (i = 0; i < arr2.length; i++) { if (arr2[i].includes(arr1[j])) { res.push(arr1[j]); ... Read More

371 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 the output should be −const output = ["abc", "abcd", "abcde"];because the first two are the substring of last.ExampleThe code for this will be −const arr = ["abc", "abcd", "abcde", "xyz"]; const findStringCombinations = (arr = []) => { let i, j, res = {}; for (i = 0; ... Read More

150 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', 'a', 'b', 'c']In this case, we should return 'a'const arr = ['75', '100', 'a', 'b', 'b', 'a']In this case, I should also get 'a'ExampleThe code for this will be −const arr = ['25', '50', 'a', 'a', 'b', 'c']; const arr1 = ['75', '100', 'a', 'b', 'b', 'a']; const getMostFrequentValue = ... Read More

539 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 this will be −const str = 'this is a string!'; const isAlpha = char => { const legend = 'abcdefghijklmnopqrstuvwxyz'; return legend.includes(char); }; const countAlphabets = (str = '') => { let count = 0; for(let i = 0; i < str.length; i++){ ... Read More

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, score: 4, isCut: false, dnf: false }, { id: 5, score: 5, isCut: true, dnf: true }, { id: 6, score: 6, isCut: true, dnf: false }, { id: 7, score: 7, isCut: true, dnf: false }, { id: 8, score: 8, isCut: true, dnf: false ... Read More

1K+ Views
Suppose, we have an array of arrays like this −const arr = [ [ ['firstName', 'Joe'], ['lastName', 'Blow'], ['age', 42], ['role', 'clerk'], [ ['firstName', 'Mary'], ['lastName', 'Jenkins'], ['age', 36], ['role', 'manager'] ] ] ];We are required to write a JavaScript function that takes in one such array. The function should construct an array of objects based on this array of arrays.The output array should ... Read More

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 = (arr = []) => { const isInteger = num => { return typeof num === 'number'; }; const el = arr.find(isInteger); return !!el; }; console.log(findInteger(arr));OutputAnd the output in the console will be −false

183 Views
We are required to write a JavaScript function that takes in any number of arrays of literals. The function should compute and return an array of cartesian product of all the elements from the arrays separating them with a dash('−').ExampleThe code for this will be −const arr1= [ 'a', 'b', 'c', 'd' ]; const arr2= [ '1', '2', '3' ]; const arr3= [ 'x', 'y', ]; const dotCartesian = (...arrs) => { const res = arrs.reduce((acc, val) => { let ret = []; acc.map(obj => { val.map(obj_1 => { ... Read More

507 Views
To find common elements in two sorted arrays using JavaScript, we will be discussing various approaches. Common element refers to element which is present in both the arrays. First, we will try brute force approach and then we will optimize our code to improve the time complexity. In this article we are having two sorted arrays, our task is to find common elements in two sorted arrays. Users must already know about JavaScript arrays, its function and operations on arrays, loops, searching technique and conditional statement. Example Input: arr1 = [1, 2, 3, 4, 5] ... Read More