
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

184 Views
ProblemWe are required to write a JavaScript function that takes in a string, str, as the only argument.The function should prepare a new string based on the input string in which the only one appearance of each character is kept and the character kept is the one which makes the result string lexicographically the smallest.For example, if the input to the function is −const str = 'cbacdcbc';Then the output should be −const output = 'acdb';Output Explanation:Note that we could have removed any occurrence of ‘c’ from the string but we removed the very first, which makes the string lexicographically the ... Read More

138 Views
ProblemWe are required to write a JavaScript function that takes in an array of strings (only lowercase string alphabets) as the first and the only argument.The function should pick two such strings from the array that shares no common characters and have the maximum product of their lengths. And then our function should return the length product of two such strings. If there exist no such strings in the array, we should return 0.For example, if the input to the function is −const arr = ["karl", "n", "the", "car", "mint", "alpha"];Then the output should be −const output = 20;Output Explanation:The ... Read More

661 Views
ProblemConsider this following situation −There are n bulbs that are initially off. We first turn on all the bulbs. Then, we turn off every second bulb. On the third round, we toggle every third bulb (turning on if it's off or turning off if it's on).In general, for the ith round, we toggle every i bulb. And lastly for the nth round, we only toggle the last bulb.We are required to write a JavaScript function that takes n as the only input and finds out how many bulbs are on after n rounds.For example, if the input to the function ... Read More

644 Views
ProblemWe are required to write a JavaScript function that takes in two arrays of single digit numbers representing two numbers, arr1 and arr2 as the first and second argument. The third argument to the function will be a number, num (num { const map = new Map(); const match = (a, b, num) => { if (map.has(a + ', ' + b + ', ' + num)) { return map.get(a + ', ' + b + ', ' + num); } let output = ... Read More

179 Views
ProblemWe are required to write a JavaScript function that takes in arr, arr, as the first argument. This array basically specifies the different types of coin denominations we have.The second argument to the function is a number, amount, which specifies the amount we want to add up to. Our function should simply return the minimum number of coins required to add up to that amount.If we can, in no way, reach amount, we should return -1.For example, if the input to the function is −const arr = [1, 2, 5]; const amount = 17;Then the output should be −const output ... Read More

206 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the only argument. Our function should sort this array in such a way that after sorting, the elements should follow this pattern −arr[0] < arr[1] > arr[2] < arr[3]....For example, if the input to the function is −const arr = [1, 5, 1, 1, 6, 4];Then the output can (there can be more than one possible answer as well) be −const output = [2, 3, 1, 3, 1, 2];ExampleThe code for this will be −const arr = [1, 5, 1, 1, 6, 4]; ... Read More

282 Views
Range SumRange sum rangeSum(i, j) is defined as the sum of the elements in an array between indices i and j (i ≤ j), inclusive.ProblemWe are required to write a JavaScript function that takes in an array of Integers, arr, as the first argument and two numbers, upper and lower as the second and third element.Our function is supposed to return the number of range sums that lie between the range [upper, lower], (both inclusive).For example, if the input to the function is −const arr = [1, 4, 3]; const upper = 5; const lower = 2;Then the output should ... Read More

322 Views
Increasing SequenceA sequence of numbers in which each succeeding element is either greater or equal to the preceding element is an increasing sequence.For instance, 4, 6, 8, 9, 11, 14 is increasing sequence 3, 3, 3, 3, 3, 3, 3 is also an increasing sequenceProblem:We are required to write a JavaScript function that takes in a 2-D array of numbers, arr, as the only argument. Our function should find and return the length of that longest path in the array that contains only increasing numbers.For example, if the input to the function is −const arr = [ [4, 5, ... Read More

126 Views
ProblemWe 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.We should, by adding elements to it, make our array such that any sum can be obtained by adding specific numbers from it between [0, num] (including both). Our function should finally return the minimum number of numbers required to add to the array so that it can produce any sum between 0 and num.For example, if the input to the function is −const arr = [1, 5, 10]; const sum = ... Read More

266 Views
Increasing Numbers:A sequence of numbers in which each succeeding element is either greater or equal to the preceding element is an increasing sequence.For instance, 4, 6, 8, 9, 11, 14 is increasing sequence 3, 3, 3, 3, 3, 3, 3 is also an increasing sequenceProblemWe are required to write a JavaScript function that takes in an array of Numbers, arr, as the only argument. The function should check whether there exist three consecutive elements in the array that are increasing.For example, if the input to the function is −const arr = [4, 1, 5, 7, 3, 1, 4];Then the output ... Read More