Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 13 of 534
JavaScript Program to Find Mth element after K Right Rotations of an Array
We are writing a JavaScript program to find the mth element after k right rotations of an array. Instead of actually rotating the array, we can calculate the final position mathematically for optimal performance. Understanding Right Rotations In a right rotation, elements move to the right, and the last element wraps around to the first position. For example, rotating [1, 2, 3, 4, 5] right by 2 positions gives [4, 5, 1, 2, 3]. Mathematical Approach The key insight is that we don't need to perform actual rotations. We can calculate where the mth element will ...
Read MoreJavaScript Program to Find the Longest Bitonic Subsequence | DP-15
We will be finding the longest bitonic subsequence in an array using dynamic programming. A bitonic subsequence is a sequence which is first increasing, then decreasing. To find the longest bitonic subsequence, we will use a two-step approach: first find the longest increasing subsequence ending at each position, then find the longest decreasing subsequence starting from each position. What is a Bitonic Subsequence? A bitonic subsequence has two parts: Increasing part: Elements are in ascending order Decreasing part: Elements are in descending order For example, in [1, ...
Read MoreJavaScript Program to Find the subarray with least average
We are going to write a program that will find the subarray with the least average. To do this, we will iterate through the array and keep track of the current subarray and its sum. For each element, we will calculate the average of the current subarray and compare it with the minimum average we have seen so far. If it is lower, we will update the minimum average and the start and end indices of the subarray. At the end of the iteration, we will return the subarray with the least average. Approach To find the subarray ...
Read MoreJavaScript Program to Form coils in a matrix
We will be using JavaScript to form coils in a matrix. The process involves manipulating the elements of the matrix to create a spiral pattern. This can be achieved by changing the direction of traversal, keeping track of the visited elements, and adjusting the indices accordingly. Approach One approach to form coils in a matrix using JavaScript would be the following − Define the size of the matrix. Initialize the matrix with zeros. Use nested loops to traverse the matrix and change the values of specific cells ...
Read MoreExplain the MUL() function in JavaScript
In this tutorial, we will learn to implement the MUL() function in JavaScript. This function demonstrates multiplication using nested functions, which create closures that maintain access to outer function variables. The MUL() function showcases JavaScript's first-class function nature, where functions can be returned from other functions. There are two ways to implement the MUL() function using nested functions: Using nested functions with names Using function currying with anonymous functions Using Nested Functions With Names In JavaScript, we can use nested functions to create a multiplication function that takes arguments one at a time. Each ...
Read MoreExplosion Animation in Canvas
In this tutorial, we will learn to create an explosion animation effect using canvas in HTML. Canvas provides a powerful way to draw dynamic graphics and animations on web pages. We'll explore two different approaches: a basic particle explosion and an interactive mouse-triggered explosion effect. Basic Particle Explosion This creates an explosion of 50 randomly colored particles that originate from the center of the canvas and move in random directions. How It Works The animation works by creating particle objects with position, velocity, and color properties. Each frame, we update particle positions and redraw them ...
Read MoreFastest way to convert JavaScript NodeList to Array
In this tutorial, we will learn the fastest way to convert JavaScript NodeList to Array. NodeList is a similar structure to an array; it is a collection of DOM (Document Object Model) elements. However, array methods like 'map()', 'filter()', and 'slice()' cannot be used on NodeList objects. There are several ways to convert NodeList to Array, but this task can be done faster using these approaches: Using Array.from() function (Recommended) Using spread operator (...) By iterating with for loop Using Array.from() (Recommended) The Array.from() method ...
Read MoreHow to change Input box borders after filling the box using JavaScript?
The style.border property is used to change an element's border styling in JavaScript. It allows you to modify the border-color, border-style, and border-width properties dynamically. This is particularly useful for providing visual feedback when users interact with form elements. We use the onchange event to trigger border changes after filling input boxes. The onchange event occurs when the value of an HTML element changes and the element loses focus. This differs from oninput, which fires immediately as the user types. The onchange event works with various form elements including text inputs, radio buttons, checkboxes, and select dropdowns. It's ...
Read MoreHow to change font style using drop-down list in JavaScript?
In JavaScript, you can change the font style of text elements using a dropdown list by combining HTML select elements with the style.fontFamily property. This creates an interactive way for users to change text appearance dynamically. A dropdown list (select element) allows users to choose from multiple font options. When a selection is made, JavaScript captures the change event and applies the selected font to target elements. Syntax The basic syntax for changing font family using JavaScript: element.style.fontFamily = "fontName"; HTML select element with options: Arial ...
Read MoreHow to change the font-weight of a text using JavaScript?
Using JavaScript is one of the most effective ways to dynamically change the font-weight of any text on your webpage. Font weight refers to the boldness or thinness of characters, ranging from 100 (thin) to 900 (black/heavy). In this article, we will explore how to change font-weight using JavaScript for both single and multiple elements. Using the Style fontWeight Property The style.fontWeight property allows us to change the font weight of individual HTML elements. This property accepts both numeric values and keyword values. Syntax document.getElementById("elementId").style.fontWeight = "normal|lighter|bold|bolder|100-900|initial|inherit"; You can assign numeric values (100-900) ...
Read More