
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

408 Views
Arithmetic Progression:An arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant.For instance, the sequence 5, 7, 9, 11, 13...Suppose we have an array that represents elements of arithmetic progression in order. But somehow one of the numbers from the progression goes missing. We are required to write a JavaScript function that takes in one such array as the first and the only argument.Then our function, in one iteration, should find and return the number which is missing from the sequence.For example −If the input array is −const arr ... Read More

2K+ Views
Suppose we have a string str containing lowercase English letters, and an array of arrays arr, where arr[i] = [direction, amount] −direction can be 0 (for left shift) or 1 (for right shift).amount is the amount by which string s is to be shifted.A left shift by 1 means remove the first character of s and append it to the end.Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.We are required to write a JavaScript function that takes in the string as the first argument and the array containing shift ... Read More

349 Views
Suppose we have a string that contains only lowercase english alphabets.For the purpose of this question, we define unit shifting of a letter as replacing that very letter to its succeeding letter in alphabets (including wrapping which means next to 'z' is 'a');We are required to write a JavaScript function that takes in a string str as the first argument and an array of numbers arr of the same length that of str as the second argument. Our function should prepare a new string in which the letters of the original string are shifted by the corresponding units present in ... Read More

341 Views
We will be given an array of arrays, each subarray consists of exactly two elements indicating the start and end time of a meeting.The task of our function is to find the maximum number of meetings one person can take avoiding the conflict of time. The function should finally return this number.For example −If the input array describing meeting times is −const arr = [[5, 40], [10, 20], [25, 35]];Then the output should be −const output = 2;because it's not possible to take all three meetings due to overlapping times but [10, 20] and [25, 35] can be attended.ExampleThe code ... Read More

188 Views
Majority Element:A majority element in an array arr of length l is an element that appears more than l/2 times and hence there is at most one such element.We need to write a JavaScript function, say isMajority() that takes an array arr which is always sorted in the increasing order as the first argument.The second argument of the function will be a number, for which we will search the array and return true if that number is the majority element or false otherwise.For example −If the input array and the number are −const arr = [5, 5, 5, 12, 15]; ... Read More

467 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 construct and return a new array that contains all such elements from the original array whose successor and predecessor are both present in the array. If means, if any element num is in the original array, it should be included in the result array if and only if num - 1 and num + 1 are also present in the array.For example −If the input array is −const arr = [4, 6, 8, 1, 9, 7, ... Read More

153 Views
We are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a single number, num, as the second argument.The function should then find two such numbers whose sum is greatest in the array but just less than the number num. If there exists no two such numbers whose sum is less than num, our function should return -1.For example −If the input array and the number are −const arr = [34, 75, 33, 23, 1, 24, 54, 8]; const num = 60;Then the output should be −const output = 58;because ... Read More

6K+ Views
We are required to write a JavaScript function that takes in a string that might contain some continuous repeating characters.The function should compress the string like this −'wwwaabbbb' -> 'w3a2b4' 'kkkkj' -> 'k4j'And if the length of the compressed string is greater than or equal to the original string we should return the original string.For example −'aab' can be compressed to 'a2b1' but it increases its length to 4 so our function should return 'aab'ExampleThe code for this will be − Live Democonst str1 = 'wwwaabbbb'; const str2 = 'kkkkj'; const str3 = 'aab'; const compressString = (str = '') => ... Read More

661 Views
In web urls if we provide space in the url, the browser automatically replaces all the spaces with the string '%20'We are required to write a JavaScript function that takes in a string as the first and the only argument. The function should then construct and return a new string in which a whitespace, wherever it was in place, replaced by '%20'For example −If the input string is −const str = 'some extra Space';Then the output should be −const output = 'some%20extra%20%20Space';ExampleThe code for this will be − Live Democonst str = 'some extra Space'; const replaceWhitespace = (str = '') ... Read More

649 Views
We are required to write a JavaScript function that takes in a string as the first and the only argument.The task of our function is to check whether any rearrangement in the characters of the string results into a palindrome string or not. If yes, then our function should return true, false otherwise.For example −If the input string is −const str = 'amadm';Then the output should be −const output = true;because the string can be rearranged to form 'madam' which is a palindrome string.ExampleThe code for this will be − Live Democonst str = 'amadm'; const canFormPalindrome = (str = '') ... Read More