Web Development Articles

Page 128 of 801

JavaScript Program to Check whether all the rotations of a given number are greater than or equal to the given number or not

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 240 Views

In this article, we will go through a JavaScript program to check whether all the rotations of a given number are greater than or equal to the given number or not. We will write an algorithm and explain every step that what we are doing. The time complexity of the code that is going to discuss will be optimistic and space complexity will all be improved from one code to another. Introduction to Problem In the problem, we are given a number and we have to check for each rotation whether they all are greater than the current ...

Read More

JavaScript Program for Count Primes in Ranges

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 4K+ Views

Prime numbers are numbers that have exactly two perfect divisors (1 and themselves). This article explores multiple methods to count prime numbers in a given range using JavaScript. We'll start with basic approaches and then optimize using the Sieve of Eratosthenes algorithm for better performance. Method 1: Direct Approach (O(N) per number) This method counts all divisors of a number. If exactly 2 divisors exist, the number is prime. function isPrime(number) { var count = 0; for (var i = 1; i

Read More

JavaScript Program for Finding a Triplet from Three Linked Lists with a Sum Equal to a Given Number

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 235 Views

In this article, we are going to implement a JavaScript program for finding a triplet from three linked lists with a sum equal to a given number. This problem is a variation of the standard three-sum problem but applied to linked lists instead of arrays. Problem Statement Given three linked lists and a target number, we need to find if there exists a triplet (one element from each list) whose sum equals the target number. If such a triplet exists, return true; otherwise, return false. Example: Target: 10 List 1: 1 → 2 → 3 ...

Read More

How to convert Title to URL Slug using JavaScript?

Aman Gupta
Aman Gupta
Updated on 15-Mar-2026 1K+ Views

Overview The conversion of a title to URL Slug is also known as "Slugify" a title. A URL Slug refers to a descriptive, readable identifier attached to a page's URL that describes the content. Converting titles to URL-friendly slugs involves using JavaScript string methods like toLowerCase(), replace(), and trim(). Algorithm Step 1 − Create HTML input elements with IDs "title" and "urlSlug" for input and output, plus a button with onclick event. Step 2 − Create a convert() function to handle the transformation. Step 3 − Get the title value using document.getElementById("title").value. Step 4 − Convert to lowercase ...

Read More

JavaScript Program for the Least Frequent Element in an Array

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 786 Views

In this program, we are given an array of integers and need to return the element that appears the least number of times. If multiple elements have the same minimum frequency, we can return any one of them. Problem Statement Given an array with duplicate numbers, we need to count the occurrence of each element and return the one with the least frequency. If multiple elements have the same minimum frequency, any one can be returned. Example 1: Input: [1, 3, 3, 5, 5, 4, 4, 4] Output: 1 Explanation: 1 appears 1 time, 3 ...

Read More

JavaScript Program for Longest Subsequence of a Number having Same Left and Right Rotation

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 279 Views

We will implement a code to find the longest subsequence of a given number that has the same left and right rotation in JavaScript. Left rotation moves the leftmost digit to the rightmost position, while right rotation moves the rightmost digit to the leftmost position. Understanding the Problem Given a number, we need to find a subsequence (formed by deleting some digits) where left and right rotations produce the same result. For example: Single digit sequences always have equal rotations: 1, 2, 3 Two identical digits: 11, 22, 33 Alternating patterns of even length: 1010, 2323, ...

Read More

JavaScript Program for Markov Matrix

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 274 Views

A matrix is a kind of 2-D array, which is in the form of some number of rows, and for each row, there is the same number of columns and by the row and column number, we can get the element at any particular index. For the Markov matrix, each row's sum must equal 1. We are going to implement a code to create a new Markov matrix and find if the currently given matrix is a Markov matrix or not. What is a Markov Matrix? A Markov matrix is a special type of matrix where each row ...

Read More

JavaScript Program for Maximize Elements Using Another Array

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 293 Views

In this article, we are going to implement a JavaScript program for maximizing elements using another array. We are given two arrays and have to pick some elements from the second array and replace the elements of the first array to maximize the sum. Problem Statement In this problem, we are given two arrays and we have to make all the elements of the first array as large as possible by replacing them with elements from the second array. Each element from the second array can only be used once. The goal is to maximize the sum of ...

Read More

JavaScript Program for Maximum Product Subarray

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 440 Views

A subarray is a contiguous portion of an array. In the maximum product subarray problem, we need to find the subarray whose elements have the largest product when multiplied together. This is a classic dynamic programming problem with interesting edge cases involving negative numbers and zeros. Problem Analysis The challenge becomes complex when dealing with different types of numbers: All positive numbers: The entire array gives maximum product Contains zeros: Array splits into segments at zero positions Contains negative numbers: Even count of negatives gives positive product, ...

Read More

How to show some custom menu on text selection?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 931 Views

In text editors like Microsoft Word, selecting text reveals a custom menu with formatting options like bold, italic, color changes, and alignment controls. This tutorial demonstrates how to create a similar custom context menu that appears when users select text on a webpage. How It Works The technique involves capturing mouse coordinates during selection and positioning a custom menu at the selection point. We use the getSelection() API to detect when text is selected and getBoundingClientRect() to calculate the menu position. Implementation Steps Step 1 − Create HTML structure with content div and hidden custom ...

Read More
Showing 1271–1280 of 8,010 articles
« Prev 1 126 127 128 129 130 801 Next »
Advertisements