- 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)
68 Views
ProblemWe are required to write a JavaScript function that takes in number, num as the only argument.Our function can do only these two operations on num: If num is even, we can replace num with num/2If num is odd, we can replace num with either num + 1 or num - 1.Using only a combination of these two operations our function is required to compute how many minimum operations it requires to bring num down to 1. The function should return the minimum number of operations.For example, if the input to the function is −const num = 7;Then the output ... Read More
254 Views
The process of randomly selecting an index from an array holds significant importance in various JavaScript applications, as it enables developers to introduce an element of unpredictability and diversity to their code. By incorporating the capability to pick an index randomly, developers can enhance the dynamism and versatility of their applications, resulting in a more engaging user experience. In this article, we will explore the intricacies of selecting an index randomly from an array in JavaScript, unraveling the underlying techniques and lesser-known methods that empower developers to introduce randomness into their array-based operations. Through a comprehensive understanding of these concepts, ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
226 Views
ProblemWe are required to write a JavaScript function that takes in two numbers, let’s call them m and n as first and the second argument respectively.The task of our function is to remove n digits from the number m so that the number m is the smallest possible number after removing n digits. And finally, the function should return the number m after removing digits.For example, if the input to the function is −const m = '45456757'; const n = 3;Then the output should be −const output = '44557';Output Explanation:We removed 5, 6 and 7 digit to get the smallest ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
296 Views
ProblemWe are required to write a JavaScript function that takes in the root of a Binary Search Tree as the only argument.The function should simply calculate the sum of data stored in the left leaves of the BST.For example, if the Tree looks like this −8 / \ 1 10 / \ 5 17Then the output should be −const output = 6;Output Explanation:Because there are two left leaves in the Tree with values 1 and 5.ExampleThe code for this will be − Live Democlass Node{ constructor(data) { this.data = data; this.left = null; ... Read More
159 Views
The quest for finding the largest sum of subarrays in JavaScript is a pursuit of paramount importance for developers seeking to optimize algorithmic efficiency and unravel the hidden potential within their data sets. In the realm of computational problem-solving, the ability to identify and compute the maximal cumulative sum of subsets within an array holds the key to unlocking insights and driving impactful decision-making processes. In this article, we embark upon a comprehensive exploration of the methodologies and techniques required to tackle this intricate challenge, employing a diverse array of rarely used words to elucidate the intricacies of JavaScript programming. ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
183 Views
ProblemSuppose, we have the following code that creates a Binary Search Tree DS and provides us with the functionality to insert node −class Node{ constructor(data) { this.data = data; this.left = null; this.right = null; }; }; class BinarySearchTree{ constructor(){ // root of a binary seach tree this.root = null; } insert(data){ var newNode = new Node(data); if(this.root === null){ this.root = newNode; }else{ ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
633 Views
ProblemWe are required to write a JavaScript function that takes in the string of characters as the only argument.Our function should prepare and a new string based on the original string in which the characters that appear for most number of times are placed first followed by number with decreasing frequencies.For example, if the input to the function is −const str = 'free';Then the output should be −const output = 'eefr';Output Explanation:Since e appears twice it is placed first followed by r and f.ExampleThe code for this will be − Live Democonst str = 'free'; const frequencySort = (str = '') ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
251 Views
ProblemWe are required to write a JavaScript function that takes in a string of characters as the only argument. Our function needs to check if the string str can be constructed by taking a substring of it and appending multiple copies of the substring together.For example, if the input to the function is −const str = 'thisthisthisthis';Then the output should be −const output = true;Output Explanation:Because the string is made by appending ‘this’ string repeatedly.ExampleThe code for this will be − Live Democonst str = 'thisthisthisthis'; const repeatedSubstring = (str = '') => { const {length} = str; const ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
327 Views
The insertRule() helps us add a rule at a defined position in the stylesheet while deleteRule() deletes a specific style on a web page. The following examples illustrate CSS rules that can be added to a stylesheet using JavaScript. Insert a Rule To insert a rule at a defined position, use the insertRule() method. The margin, padding, and box-shadow is also set. First, the custom id is set using the getElementById() − let newSheet = document.getElementById('custom').sheet let cs = 'p {'; cs += 'margin: 4%;'; cs += 'padding: 2%;'; cs += 'font-size: 22px;'; cs += 'box-shadow: ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
377 Views
Using JavaScript, we can set our TextArea element to automatically grow with its content. The following examples illustrate how we can achieve the above scenario. Let us say the following is our TextArea before adding content − The following is the TextArea after adding content − The following is the same TextArea that auto grows itself after adding more content − Auto Grow a Textarea Example Let us see how to auto grow a textarea − * { ... Read More