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
Returning the first number that equals its index in an array using JavaScript
Problem We need to write a JavaScript function that takes an array of numbers and returns the first number whose value equals its 0-based index position. This means we're looking for an element where array[i] === i. Example Following is the code − const arr = [9, 2, 1, 3, 6, 5]; const findFirstSimilar = (arr = []) => { for(let i = 0; i < arr.length; i++){ const el = arr[i]; if(el === i){ ...
Read MoreMaximum average of a specific length of subarray in JavaScript
Problem We are required to write a JavaScript function that takes in an array of integers, arr, as the first argument and a number, num, as the second argument. Our function should find the contiguous subarray of given length num that has the maximum average value. And we need to output the maximum average value. Example Input and Output For example, if the input to the function is: const arr = [1, 12, -5, -6, 50, 3]; const num = 4; The expected output is: 12.75 Output Explanation: ...
Read MoreHow to create a canvas with progress cursor on hover over objects using FabricJS?
In this article, we are going to create a canvas with a progress cursor on hover using FabricJS. The progress cursor is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors such as default, all-scroll, crosshair, col-resize, row-resize, etc. that reuse the native cursor under the hood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Canvas(element: HTMLElement|String, { hoverCursor: String }: Object) Parameters ...
Read MoreHow to call the constructor of a parent class in JavaScript?
In JavaScript, when working with inheritance, you often need to call the parent class constructor from the child class. This is accomplished using the super() method, which provides access to the parent's constructor and methods. What is a Constructor? A constructor is a special method that runs when creating a new instance of a class. It's used to initialize object properties and set up the object's initial state. In JavaScript, constructors are defined using the constructor keyword within a class. Inheritance in JavaScript Inheritance allows objects to access properties and methods from parent objects. Child classes ...
Read MoreHow to set the scale factor (border) of a Circle using FabricJS?
In this tutorial, we are going to set the scale factor (border) of Circle using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we have to create an instance of fabric.Circle class and add it to the canvas. We can use the borderScaleFactor property which specifies the scale factor of objects controlling borders. Syntax new fabric.Circle({ borderScaleFactor: Number }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to ...
Read MoreHow to set the width of a Triangle using FabricJS?
In this tutorial, we are going to learn how to set the width of a 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 manipulate a triangle object by changing its position, opacity, stroke and also its dimension. FabricJS allows us to control an object's dimensions by using the width and height properties. Syntax new fabric.Triangle({ width: Number }: Object) Parameters ...
Read MoreHow to uncurry a function up to depth n in JavaScript?
In JavaScript, a function is considered "curried" if it takes one or more arguments and returns a new function that expects the remaining arguments. Currying is a powerful technique that can be used to create new functions from existing ones, or to "uncurry" a function up to depth n. Why do we uncurry a function? There are several reasons why you might want to uncurry a function. For example, you may want to − Use a curried function in a context where a non-curried function is expected Convert ...
Read MoreFabricJS – How to exclude Line object from being saved while using JSON.stringify()?
In this tutorial, we are going to learn how to exclude Line object from being saved while using JSON.stringify() in FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. Serialization is used in order to export canvas contents. In order to achieve this we use toObject() ...
Read MoreHow to use await outside of an async function in JavaScript?
In JavaScript, the await keyword can only be used inside async functions. However, there are several techniques to work with asynchronous code when you need to use await at the top level or outside of async functions. Here, we will learn different approaches to handle asynchronous operations outside of regular async functions. Using Immediately Invoked Function Expression (IIFE) The most common approach is to wrap your code in an immediately invoked async function expression. This allows you to use await within the function scope. Syntax (async () => { let ...
Read MoreHow to calculate days left until next Christmas using JavaScript?
In this article, you will learn how to calculate the days remaining until the next Christmas using JavaScript. We'll use the Date object to work with dates and perform time calculations to determine how many days are left until December 25th. Understanding the Logic To calculate days until Christmas, we need to: Get today's date Determine the next Christmas date (this year or next year) Calculate the time difference in milliseconds Convert milliseconds to days Method 1: Direct Calculation In this approach, we calculate the time difference without using functions: let todayDate ...
Read More