
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

514 Views
We are required to write a JavaScript function that takes in an array of integers as the first and the only argument.The function should find and return the length of the longest consecutive increasing sequence that exists in the array (contiguous or non-contiguous).For example −If the input array is −const arr = [4, 6, 9, 1, 2, 8, 5, 3, -1];Then the output should be 6 because the longest consecutive increasing sequence is 1, 2, 3, 4, 5, 6.ExampleFollowing is the code −const arr = [4, 6, 9, 1, 2, 8, 5, 3, -1]; const consecutiveSequence = (arr = []) ... Read More

2K+ Views
We are required to write a JavaScript function that takes in an array of literals as the first and the only argument.The function should construct and return an array of all possible subarrays that can be formed from the original array.For example −If the input array is −const arr = [1, 2, 3];Then the output should be −const output = [ [2], [1], [3], [1, 2, 3], [2, 3], [1, 2], [1, 3], [] ];The order of subarrays is not that important.ExampleFollowing is the code −const arr = [1, 2, 3]; const ... Read More

483 Views
We are required to write a JavaScript function that takes in an array of arrays of characters as the first argument and a string as the second argument.The function should find out whether there exist characters in the matrix, non-repeating combination of which yields the string provided to the function as the second argument.If there exists such a combination, our function should return true, false otherwise.For example −If the input array and the string are −const arr = [ ['s', 'd', 'k', 'e'], ['j', 'm', 'o', 'w'], ['y', 'n', 'l'] ]; const str = 'don';Then the output ... Read More

100 Views
We are required to write a JavaScript function that takes in an array of arrays of numbers as the first argument and a number as the second argument. The subarrays contain numbers sorted in an increasing order and no element of a preceding subarray is greater than any element of the succeeding subarray.The function should use the binary search algorithm to search for the element provided as the second argument in the sorted array of arrays.If the element exists the function should return true, false otherwise.For example −If the input array is −const arr = [ [2, 6, 9, ... Read More

862 Views
We are required to write a JavaScript function that takes in array of integers as the first and the only argument.Our function should find and return that smallest positive integer which is not present in the array.For example −If the input array is −const arr = [4, 2, -1, 0, 3, 9, 1, -5];Then the output should be −const output = 5;because 1, 2, 3, 4 are already present in the array and 5 is the smallest positive integer absent from the array.ExampleFollowing is the code −const arr = [4, 2, -1, 0, 3, 9, 1, -5]; const findSmallestMissing = ... Read More

292 Views
We are required to write a JavaScript function that takes in an array of numbers as the first argument and a number as the second argument. The function should prepare and return an array of all such triplets (consecutive or nonconsecutive), that add up to the number specified by the second argument.For example −If the input array and the number are −const arr = [4, 2, 0, 1, 2, 6, 8, 3, 2, 5]; const num = 8;Then the output array should be −const output = [ [ 2, 2, 4 ], [ 1, 3, 4 ], [ 0, 2, ... Read More

437 Views
We are required to write a JavaScript function that takes in two numbers, let’s say m and n as arguments.n will always be smaller than or equal to the number of digits present in m. The function should calculate and return the sum of first n digits of m.For example −If the input numbers are −const m = 5465767; const n = 4;Then the output should be −const output = 20;because 5 + 4 + 6 + 5 = 20ExampleFollowing is the code −const m = 5465767; const n = 4; const digitSumUpto = (m, n) => { if(n ... Read More

389 Views
We are required to write a JavaScript function that takes in a positive integer as the first and the only argument.The function should find one such smallest prime number which is just greater than the number specified as argument.For example −If the input is −const num = 18;Then the output should be:const output = 19;ExampleFollowing is the code:const num = 18; const justGreaterPrime = (num) => { for (let i = num + 1;; i++) { let isPrime = true; for (let d = 2; d * d

339 Views
We are required to write a JavaScript function that takes in a sentence as the first and the only argument.A sentence is a special kind of string of characters joined by finite number of whitespaces.The function should rearrange the words of the sentence such that the smallest word (word with least characters) appears first and then followed by bigger ones.For example −If the input string is −const str = 'this is a string';Then the output should be −const output = 'a is this string';ExampleFollowing is the code −const str = 'this is a string'; const arrangeWords = (str = []) ... Read More

336 Views
We are required to write a JavaScript function that takes in an array of literals as the first and the only argument.The array is likely to contain many repeating values. Our function should sort the array such that the values that are unique or that have the least frequency are placed before the ones that have the most.For example −If the input array is −const arr = [4, 7, 3, 5, 5, 4, 7, 9, 2, 1, 5, 7, 5, 5, 9];Then the output array should be −const output = [ 3, 2, 1, 9, 9, 4, 4, ... Read More