- 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
93 Views
Good BaseFor an integer num, we call k (k >= 2) a good base of num, if all digits of num base k are 1.For instance: 13 base 3 is 111, hence 3 is a good base for num = 13ProblemWe are required to write a JavaScript function that takes in string str that represents a number as the only argument. The function should return the string representation of the smallest possible number which is a good base for str.For example, if the input to the function is −const str = "4681";Then the output should be −const output = "8";Output ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
118 Views
ProblemWe are required to write a JavaScript function that takes in a binary array (an array that consists of only 0 and 1), arr, as the only argument. Our function should find the maximum number of consecutive 1s in this array if we can flip at most one 0.For example, if the input to the function is −const arr = [1, 0, 1, 1, 0];Then the output should be −const output = 4;Output ExplanationIf we flip the 0 at index 1 in the array, we will get 4 consecutive 1s.ExampleThe code for this will be − Live Democonst arr = [1, ... Read More
![Naveen Singh](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 array of Integers, arr, as the first and the only argument.Our function should count the occurrence of all such index pairs (i, j) that satisfy the following conditions −I < j, andarr[i] > 2 * arr[j]For example, if the input to the function is −const input = [2, 4, 3, 5, 1];Then the output should be −const output = 3;Output Explanation:Because the three desired pairs are −[4, 1], [3, 1] and [5, 1]ExampleThe code for this will be − Live Democonst arr = [2, 4, 3, 5, 1]; const ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
68 Views
ProblemWe are required to write a JavaScript function that takes in an array of Integers, arr, as the first argument and a single integer, target, as the second argument.For each Integer in the array, our function can either assign ‘+’ or ‘-’ to it.Our function should find out how many ways in total exist to assign ‘+’, ‘-’ to make the sum of integers of the array equal to the target sum, target.For example, if the input to the function is −const arr = [1, 1, 1, 1, 1]; const target = 3;Then the output should be −const output = ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
681 Views
Problem:We are required to write a JavaScript function that takes in a square matrix (an array of arrays having the same number of rows and columns). The function should traverse diagonally through that array of array and prepare a new array of elements placed in that order it encountered while traversing.For example, if the input to the function is −const arr = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ];Then the output should be −const output = [1, 2, 4, 7, 5, 3, 6, 8, 9];Example Live DemoThe code for this will be −const arr ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
224 Views
Mode:Mode of a set of data is simply the number that occurs for most number of times in that set of data. For instance, 3 is the mode of dataset 2, 3, 1, 3, 4, 2, 3, 1 as it occurs for most number of times.Binary Search TreeA tree DS is a valid Binary Search Tree if it fulfils the following conditions −The left subtree of a node contains only nodes with keys less than or equal to the node's key.The right subtree of a node contains only nodes with keys greater than or equal to the node's key.Both the ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
209 Views
Circular ArrayAn array in which the next element of the last element is the first element of the array is often termed as circular.Obviously, there exists no such mechanism to store data like this, data will still be stored in continuous memory blocks and circular arrays are more like an idea than reality.ProblemWe are required to write a JavaScript function that takes in a circular array of Integers, arr, as the first and the only argument.The function should then construct and return an array that contains the next greater element for each corresponding element of the original array. The Next ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
679 Views
ProblemWe are required to write a JavaScript function that takes in an array, arr, of numbers as the only argument.The array basically consists of the marks scored by some students, based on the array of marks, our function should prepare and return an array of ranks which should contain the rank of corresponding students on the basis of how high their marks are in the marks array arr.For instance, for the highest entry in array arr, the corresponding entry in output array should be 1, 2 for second highest and so on.For example, if the input to the function is ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
Tree Data StructureA tree is a collection of nodes connected by some edges. Conventionally, each node of a tree holds some data and reference to its children.Binary Search TreeBinary Search tree is a binary tree in which nodes that have lesser value are stored on the left while the nodes with a higher value are stored at the right.For instance, visual representation of a valid BST is − 25 / \ 20 36 / \ / \ 10 22 30 40Let’s now implement our very own Binary Search ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
138 Views
SubsequenceFor the purpose of this problem, we define a subsequence as a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Any string is a subsequence of itself and an empty string is a subsequence of any string.ProblemWe are required to write a JavaScript function that takes in an array of strings as the only argument. Our function needs to find the length of the longest uncommon subsequence among them.By longest uncommon subsequence we mean, longest subsequence of one of the strings in the array and this subsequence should ... Read More