
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

620 Views
For the purpose of this question, we define an interval as an array of two numbers where the first number is always smaller than the second number.For example −[4, 6], [2, 3], [6, 8], [2, 7], [1, 8] are all examples of valid intervals.Suppose, we have an array of intervals which is sorted according to the their start times (the first elements of each interval).The intervals in the array are non-overlapping which means that for any two arbitrary adjacent intervals, [m, n], [x, y] m < n < x < yTherefore, one such example of this array of intervals can ... Read More

304 Views
Suppose we have an array of Numbers that contains any frequency of exactly three elements - 1, 0 and 1 like this −const arr = [1, 1, 0, -1, 1, 0, -1, 1, 0, 0, 1];We are required to write a JavaScript function that takes in one such array. The function should simply sort this special array in place i.e., without using any extra array to store the values.The only condition is that our function should be a linear time function (using only one iteration).ExampleFollowing is the code −const arr = [1, 1, 0, -1, 1, 0, -1, 1, 0, ... Read More

279 Views
We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument.The function should then try removing one such element from the array, upon removal of which, the sum of elements at odd indices is equal to the sum of elements at even indices. In the way, the function should count all the possible unique ways in which we can remove one element at a time to achieve the required combination.For example −If the input array is −const arr = [2, 6, 4, 2];Then the output should be 2 because, ... Read More

614 Views
Suppose we have an array of objects like this −const arr = [{ name: 'Dinesh Lamba', age: 23, occupation: 'Web Developer', }, { address: 'Vasant Vihar', experience: 5, isEmployed: true }];We are required to write a JavaScript function that takes in one such array of objects. The function should then prepare an object that contains all the properties that exist in all the objects of the array.Therefore, for the above array, the output should look like −const output = { name: 'Dinesh Lamba', age: 23, occupation: 'Web Developer', address: 'Vasant ... Read More

135 Views
We are required to write a JavaScript function that takes in an array of integers as the first argument and an integer as the second argument.The function should check whether we can create n (second argument) subarrays from the original array such that all the subarrays have the equal sum.For example −If the inputs are −const arr = [4, 3, 2, 3, 5, 2, 1]; const num = 4;The output should be true because the subarrays are: [5], [1, 4], [2, 3], [2, 3] all having sum equal to 5.ExampleFollowing is the code −const arr = [4, 3, 2, 3, ... Read More

1K+ Views
Tribonacci Series:The tribonacci sequence is a generalization of the Fibonacci sequence where each term is the sum of the three preceding terms.For example, the first few terms of the tribonacci series are −0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149We are required to write a JavaScript function that takes in a number, say num, as the only argument.The function should then return an array of num elements, containing the first num terms of the tribonacci series.For example:f(6) = 0, ExampleFollowing is the code:const tribonacci = (num = 1) => { if (num === 0 || num ... Read More

878 Views
Identity MatrixAn identity Matrix is a matrix which is n × n square matrix where the diagonal consist of ones and the other elements are all zeros.For example an identity matrix of order is will be −const arr = [ [1, 0, 0], [0, 1, 0], [0, 0, 1] ];We are required to write a JavaScript function that takes in a number, say n, and returns an identity matrix of n*n order.ExampleFollowing is the code −const num = 5; const constructIdentity = (num = 1) => { const res = []; for(let i = 0; ... Read More

772 Views
We are required to write a JavaScript function that takes in a string that might contain some alphabets. The function should count and return the number of vowels that exists in the string.ExampleFollowing is the code −const str = 'this is a string'; const countVowels = (str = '') => { str = str.toLowerCase(); const legend = 'aeiou'; let count = 0; for(let i = 0; i < str.length; i++){ const el = str[i]; if(!legend.includes(el)){ continue; }; count++; }; return count; }; console.log(countVowels(str));OutputFollowing is the output on console −4

791 Views
We are required to write a JavaScript function that takes in a string as the only argument. The function should generate an array of strings that contains all possible contiguous substrings that exist in the array.ExampleFollowing is the code −const str = 'Delhi'; const allCombinations = (str1 = '') => { const arr = []; for (let x = 0, y=1; x < str1.length; x++,y++) { arr[x]=str1.substring(x, y); }; const combination = []; let temp= ""; let len = Math.pow(2, arr.length); for (let i = 0; i < len ; i++){ temp= ""; for (let j=0;j

3K+ Views
We are required to write a JavaScript function that takes in a floating-point number up to 2 digits of precision.The function should convert that number into the Indian current text.For example −If the input number is −const num = 12500Then the output should be −const output = 'Twelve Thousand Five Hundred';ExampleFollowing is the code −const num = 12500; const wordify = (num) => { const single = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]; const double = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"]; const tens = ["", "Ten", "Twenty", "Thirty", ... Read More