Articles on Trending Technologies

Technical articles with clear explanations and examples

What is the best way to search for an item in a sorted list in JavaScript?

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

When searching for an item in a sorted array in JavaScript, binary search is the most efficient approach. Unlike linear search which checks every element, binary search takes advantage of the sorted order to eliminate half the search space with each comparison. What is Binary Search? Binary search is a divide-and-conquer algorithm that works on sorted arrays. It compares the target value with the middle element and eliminates half of the remaining elements at each step. This approach has O(log n) time complexity, making it much faster than linear search's O(n). How Binary Search Works The ...

Read More

Checking if an array is sorted lexicographically in reference to some scrambled alphabet sequence in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 399 Views

We need to write a JavaScript function that checks if an array of words is sorted lexicographically according to a custom alphabet order. The function takes two arguments: an array of words and a string representing the custom alphabetical order. The task is to verify whether the words are arranged correctly based on the given alphabet sequence. If they are properly sorted, return true; otherwise, return false. Problem Understanding Consider this example: const arr = ['this', 'is', 'something', 'mad']; const order = 'hdetljnopqabcuvwxfgirsykmz'; In the custom order, 't' comes before 'i', 'i' comes ...

Read More

Building an array of specific size with consecutive element sum being perfect square in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 244 Views

We need to create a JavaScript function that arranges numbers 1 to n such that the sum of each pair of consecutive elements forms a perfect square. This is a classic backtracking problem that requires careful arrangement of numbers. Problem Understanding For an array of size n, we must arrange integers 1 through n where each adjacent pair sums to a perfect square. For example, if two consecutive numbers are 9 and 7, their sum (16) should be a perfect square (4²). Algorithm Approach We use a backtracking algorithm with these steps: Try each ...

Read More

Limiting string up to a specified length in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

Truncating strings to a specified length is a common requirement in JavaScript applications, especially for displaying previews or fitting text within UI constraints. This article shows how to limit string length and append ellipsis when truncation occurs. Problem We need to write a JavaScript function that takes a string and a number. The function should return the truncated version of the string up to the given limit followed by "..." if the result is shorter than the original string. Otherwise, it should return the same string if nothing was truncated. Using String.slice() Method The most straightforward ...

Read More

Can one string be repeated to form other in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

We are required to write a JavaScript function that takes in two strings, str1 and str2, as the first and the second argument. Our function should return the minimum number of times we should repeat string str1 so that string str2 is a substring of it. If it is impossible for str2 to be a substring after repeating it, we should return -1. Problem Example For example, if the input to the function is: const str1 = 'wxyz'; const str2 = 'yzwxyzwx'; The expected output is 3, because by repeating str1 three times ...

Read More

How to enable JavaScript in Chrome, Firefox, and Safari?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 1K+ Views

JavaScript has become an essential part of modern websites. Nearly every website requires JavaScript support to function properly. All major browsers include a setting to enable or disable JavaScript. When JavaScript is disabled, websites may not work correctly, preventing users from accessing important features and interactive elements. To ensure websites function properly, you need to enable JavaScript in your browser. Here's how to enable JavaScript in the three most popular browsers: Google Chrome Mozilla Firefox Safari Google Chrome Follow these steps to ...

Read More

How to set the minimum allowed scale value of a Triangle using FabricJS?

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

In this tutorial, we are going to learn how to set the minimum allowed scale of Triangle using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we will have to create an instance of fabric.Triangle class and add it to the canvas. We can customize a triangle object by adding a fill colour to it, eliminate its borders or even make changes in its dimensions. Similarly, we can also set its minimum allowed scale by using the minScaleLimit property. Syntax new fabric.Triangle({ minScaleLimit : Number }: Object) ...

Read More

How to make active tab in navigation menu using HTML CSS & JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 14K+ Views

Creating an active tab navigation menu helps users understand which page or section they're currently viewing. This tutorial demonstrates how to build an interactive navigation menu using HTML, CSS, and JavaScript with proper active state management. HTML Structure The HTML structure uses a simple unordered list with navigation items. Each li element represents a tab, and anchor tags provide the clickable links. Home About Services Portfolio Contact CSS Styling The CSS creates the visual design and ...

Read More

How to center a Text object vertically on canvas using FabricJS?

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

In this tutorial, we are going to learn how to center a Text object vertically on canvas using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can also center the text object vertically on the canvas by using the centerV() method. Syntax centerV() This method centers the text ...

Read More

How to use array that include and check an object against a property of an object?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

The task is to check whether the array contains a particular value. Also, we need to check if the array contains the particular object with the given property. This tutorial will use the array.includes() and array.some() methods to check whether the array contains the value or object with a particular property. Use the array.includes() method to check values exist in the array The array.includes() method allows us to check whether the array contains any value. In simple terms, we can search for values in the array using the array.includes() method. Syntax array.includes(value, startIndex); ...

Read More
Showing 15541–15550 of 61,298 articles
Advertisements