Articles on Trending Technologies

Technical articles with clear explanations and examples

sorting array of numbers into sets in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 361 Views

In JavaScript, we often need to sort an array of numbers and convert it into a Set data structure. This process involves understanding how JavaScript's sort method works with numbers and how to properly convert arrays to Sets. Understanding JavaScript Arrays An array in JavaScript is a collection of elements stored under one roof. Unlike arrays in other languages, JavaScript arrays are objects with built-in properties and methods that make data manipulation easier. const arrayExample = [100, 200, 500, 600]; console.log(arrayExample); [100, 200, 500, 600] The Problem with JavaScript's Sort Method ...

Read More

Function to reverse a string JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 631 Views

In JavaScript, reversing a string is a common programming task that can be accomplished using various approaches. This tutorial demonstrates how to create a function that reverses any given string by iterating through its characters in reverse order. Understanding the Problem String reversal means rearranging the characters of a string so that the last character becomes first, second-last becomes second, and so on. For example, if we have the string "Hello", the reverse will be "olleH". Algorithm Step 1 − Declare a variable to store the reversed string and initialize it as empty. Step 2 − ...

Read More

Constructing largest number from an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 612 Views

We need to write a JavaScript function that takes an array of numbers and arranges them to form the largest possible number by concatenating the digits. The key insight is that we can't simply sort numbers in descending order. For example, with numbers [3, 30], sorting gives [30, 3] → "303", but the correct answer is [3, 30] → "330". For example − If the input array is − const arr = [5, 45, 34, 9, 3]; Then the output should be − '954543' Algorithm The solution uses ...

Read More

Next multiple of 5 and binary concatenation in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 165 Views

We need to write a JavaScript function that takes a number and finds the next higher multiple of 5 by concatenating the shortest possible binary string to the number's binary representation. Problem Given a number n, we want to: Convert n to binary representation Append the shortest binary string to make it divisible by 5 Return the resulting decimal number How It Works The algorithm generates all possible binary combinations of increasing length until it finds one that, when concatenated to the original number's binary form, creates a number divisible by 5. Example ...

Read More

How to add stroke to a Circle using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 351 Views

In this tutorial, we are going to learn how to add stroke to a Circle using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will create an instance of fabric.Circle class and add it to the canvas. Our circle object can be customized in various ways like changing its dimensions, adding a background color or by changing the colour of the line drawn around the object. We can do this by using the stroke property. Syntax new fabric.Circle({ stroke: String }: Object) Parameters ...

Read More

How to open a webcam using JavaScript?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 20K+ Views

In this tutorial, we will learn how to open a webcam using JavaScript. This can be accomplished using WebRTC (Web Real-Time Communication), which allows us to access and capture webcam and microphone devices on the user's system. Understanding getUserMedia() We can access the user's webcam and microphone using the navigator.mediaDevices.getUserMedia() method. This function requires user permission and returns a Promise that resolves when access is granted. Basic Implementation Steps Follow these steps to implement webcam access: STEP 1 − Create HTML elements including a video element for the webcam stream and a ...

Read More

Two sum problem in linear time in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 2K+ Views

The Two Sum Problem is a classic algorithmic challenge that asks us to find two numbers in an array that add up to a specific target value. This article demonstrates how to solve this problem efficiently in linear time using JavaScript. What is the Two Sum Problem? The Two Sum Problem requires finding a pair of indices in an array of numbers that add up to a given target sum. Given an array of integers and a target sum, we need to return the indices of two numbers that sum to the target value. The key constraint ...

Read More

Implementing counting sort in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

In the given task, our aim is to create a counting sorting technique and implement this problem with the help of Javascript functionalities. What is Counting Sort? Counting sort is a non-comparison based sorting algorithm that works by counting the occurrences of each distinct element in the input array. It determines the position of each element in the sorted output by calculating how many elements are smaller than it. The algorithm works in several phases: Find the minimum and maximum values in the input array Create a count array to ...

Read More

Finding special kind of elements with in an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 140 Views

This article explains how to find special pairs of elements in an array where both the value difference and index difference meet specific criteria. Problem Statement We need to write a JavaScript function that takes three arguments: arr --> an array of integers m --> maximum allowed index difference n --> maximum allowed value difference The function should find if there exist two elements (a1 and a2) such that: The absolute difference between a1 and a2 is at most n The absolute difference between the indices of a1 and a2 is at ...

Read More

Repeating string for specific number of times using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

JavaScript provides several methods to repeat a string for a specific number of times. This functionality is useful for generating patterns, creating padding, or building repeated text sequences in web applications. Problem Statement Write a JavaScript function that takes a string and a positive integer as input and returns a new string that repeats the input string for the specified number of times. If the input string is empty or the specified number of times is zero, the function should return an empty string. Sample Input: String: "Hello" Number of Times: 3 Sample Output: ...

Read More
Showing 14781–14790 of 61,297 articles
Advertisements