- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 6683 Articles for Javascript
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
140 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
200 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
248 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
56 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
212 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
209 Views
ProblemWe are required to write a JavaScript function that takes in an array of strings as the only argument. The function is supposed to return an array of arrays of all the index pairs joining the strings at which yields a new palindrome string.For example, if the input to the function is −const arr = ['tab', 'cat', 'bat'];Then the output should be −const output = [[0, 2], [2, 0]];Output Explanation:Because both the strings ‘battab’ and ‘tabbat’ are palindromes.ExampleThe code for this will be −const arr = ['tab', 'cat', 'bat']; const isPalindrome = (str = '') => { let i ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
355 Views
ProblemWe are required to write a JavaScript function that takes in a single Integer, num, as the first and the only argument. Our function should prepare an array for every number between 0 and num (including both of them), for each number, the corresponding element should be the number of 1s contained in the binary representation of that number.For example, if the input to the function is −const num = 4;Then the output should be −const output = [0, 1, 1, 2, 1];Output Explanation:Because 0 contains 0 1s in its binary form 1 contains 1, and so on.ExampleThe code for ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
391 Views
ProblemWe are required to write a JavaScript function that takes in a nested array, arr (nested up to any level) as the only argument.The function should calculate the weighted sum of the nested array and return that sum.For calculating nested sum, we multiply a specific element with its level of nesting and add throughout the array.For example, if the input to the function is −const arr = [4, 7, [6, 1, [5, 2]]];Then the output should be −const output = 46;Output Explanation:The sum will be calculated like this −(4 * 1) + ( 7 * 1) + (6 * 2) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
292 Views
ProblemWe are required to write a JavaScript function that takes in a single integer, num, as the only argument. Our function should check whether this number is a valid power of 4 or not. If it is a power of 4, we should return true, false otherwise.For example, if the input to the function is −const num1 = 2356; const num2 = 16;Then the output should be −const output1 = false; const output2 = true;ExampleThe code for this will be −const num1 = 2356; const num2 = 16; const isPowerOfFour = (num = 1) => { let bool = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
79 Views
ProblemWe are required to write a JavaScript function that takes in an Integer, num, as the first and the only argument.Our function should break these integers into at least two chunks which when added gives the sum integer num and when multiplied gives maximum possible product. Finally, our function should return this maximum possible product.For example, if the input to the function is −const num = 10;Then the output should be −const output = 36;Output Explanation:Because 10 can be broken into 3 + 3 + 4 which when multiplied gives 36.ExampleThe code for this will be −const num = 10; ... Read More