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
Finding desired sum of elements in an array in JavaScript
Finding groups of elements in an array that sum to a desired value is a common programming problem. This involves checking combinations of consecutive elements to match both a target sum and group size. Problem Statement Given an array of numbers, we need to find how many consecutive groups of a specific length sum up to a target value. For example: const arr = [1, 2, 1, 3, 2]; const sum = 3; const num = 2; We want to find groups of 2 consecutive elements that sum to 3. The groups [1, 2] ...
Read MoreHow to set the color of controlling corners of Ellipse using FabricJS?
In this tutorial, we are going to set the color of controlling corners of Ellipse using FabricJS. The cornerColor property allows us to manipulate the color of the controlling corners when the object is active. Syntax new fabric.Ellipse({ cornerColor: String }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. Using this parameter color, cursor, stroke width and a lot of other properties can be changed related to the object of which the cornerColor is ...
Read MoreHow to create a canvas with Triangle using FabricJS?
In this tutorial, we are going to learn about how to create a canvas with a Triangle object 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. Syntax new fabric.Triangle({ width: Number, height: Number }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our triangle. Using this parameter, properties such as ...
Read MoreHow to set the angle of rotation of a Textbox using FabricJS?
In this tutorial, we are going to set the angle of rotation of a Textbox using FabricJS. We can customize, stretch or move around the text written in a textbox. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. The angle property in FabricJS defines the angle of 2D rotation of an object. We also have the centeredRotation property that allows us to use the center point of a textbox as the origin of transformation. Syntax new fabric.Textbox(text: String, { angle: Number, centeredRotation: Boolean ...
Read MoreHow to change the cursor width in IText using FabricJS?
In this tutorial, we are going to learn about how to change the cursor width in IText object using FabricJS. The IText class was introduced in FabricJS version 1.4, extends fabric.Text and is used to create IText instances. An IText instance gives us the freedom to select, cut, paste or add new text without additional configurations. There are also various supported key combinations and mouse/touch combinations which make text interactive which are not provided in Text. Textbox, however, which is based on IText allows us to resize the text rectangle and wraps lines automatically. This is not true for ...
Read MoreHow to implement multiple input checkbox in vanilla JavaScript?
We will learn how to implement multiple input checkbox functionality in vanilla JavaScript. The checkbox input selector will have the following features: Multiple options can be selected using checkboxes Chosen options will be displayed as a separate list with visual indicators Delete icon will be provided against each chosen option to uncheck/remove that option We will implement this functionality using only HTML, CSS, and JavaScript without any third-party libraries. Approach Create an object where keys represent checkbox labels and values (true/false) ...
Read MoreFinding the inclination of arrays in JavaScript
We are required to write a JavaScript function that takes in an array of numbers and returns true if it's either strictly increasing or strictly decreasing, otherwise returns false. In Mathematics, a strictly increasing function is that function in which the value to be plotted always increases. Similarly, a strictly decreasing function is that function in which the value to be plotted always decreases. Understanding the Concept An array has a consistent inclination when: Strictly increasing: Each element is greater than the previous one Strictly decreasing: Each element ...
Read MoreSorting strings with decimal points in JavaScript
In JavaScript, sorting strings with decimal points requires converting them to numbers first, since string comparison would treat "10.0" as less than "2.0". This article demonstrates how to sort decimal string arrays properly. Understanding the Problem When sorting strings containing decimal numbers, JavaScript's default string comparison doesn't work numerically. For example, ['3.3', '4.4', '2.3', '1.2'] should become ['1.2', '2.3', '3.3', '4.4'], but string sorting would give incorrect results. The Solution Approach To solve this problem, we need to: Convert decimal strings to numbers using parseFloat() Sort the numbers numerically Convert back to strings if needed ...
Read MoreMaximum sum of n consecutive elements of array in JavaScript
In JavaScript, finding the maximum sum of n consecutive elements in an array is a classic sliding window problem. This technique efficiently calculates the maximum sum by maintaining a window of fixed size and sliding it across the array. Understanding the Problem The goal is to find a continuous subarray of length n within the given array that has the highest possible sum. For example, given array [1, 2, 4, 7, 3, 5] and n = 3, the consecutive elements [4, 7, 3] have the maximum sum ...
Read MoreFinding a pair that is divisible by some number in JavaScript
We need to write a JavaScript function that finds all pairs of numbers from an array whose sum is divisible by a given number. The function takes an array of numbers and a divisor as parameters. Problem Statement Given an array of numbers and a divisor, find all pairs where: (arr[i] + arr[j]) % divisor === 0, and i < j For example, with array [1, 2, 3, 4, 5, 6] and divisor 4, we need pairs whose sum is divisible by 4. Input and Expected Output Input: const arr = ...
Read More