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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Checking if an array is sorted lexicographically in reference to some scrambled alphabet sequence in JavaScript
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 MoreBuilding an array of specific size with consecutive element sum being perfect square in JavaScript
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 MoreLimiting string up to a specified length in JavaScript
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 MoreCan one string be repeated to form other in JavaScript
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 MoreHow to enable JavaScript in Chrome, Firefox, and Safari?
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 MoreHow to set the minimum allowed scale value of a Triangle using FabricJS?
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 MoreHow to make active tab in navigation menu using HTML CSS & JavaScript?
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 MoreHow to center a Text object vertically on canvas using FabricJS?
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 MoreHow to use array that include and check an object against a property of an object?
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 MoreReturn the sum of two consecutive elements from the original array in JavaScript
An Array is known as collection of similar data elements which are stored at contiguous memory locations. Array is such a simple data structure where we can access each data element in the array with the help index numbers, which starts from 0. The following is the basic declaration of array in JavaScript − const mobiles = ["SAMSUNG", "ONEPLUS", "APPLE"]; Sum of Two Consecutive Elements of an Array We are required to write a JavaScript function that takes in an array of Numbers and returns a new array with elements as sum of two ...
Read More