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
Sum excluding one element in JavaScript
In JavaScript, when you need to find the minimum and maximum possible sums by excluding exactly one element from an array, you can solve this efficiently using a single loop approach. The key insight is that to get the minimum sum (excluding one element), you remove the largest element. To get the maximum sum (excluding one element), you remove the smallest element. Problem Statement Given an array of integers, return an array with two values: First integer: smallest possible sum excluding any one element Second integer: greatest ...
Read MoreHow to disable the selectability of Circle using FabricJS?
In this tutorial, we are going to learn how to disable selectability of a Circle using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will have to create an instance of fabric.Circle class and add it to the canvas. In order to modify an object, we have to select it in FabricJS. However, we can change this behaviour by using the selectable property. Syntax new fabric.Circle({ selectable: Boolean }: Object) Parameters ...
Read MoreHow to set the alignment of text in a Textbox using FabricJS?
In this tutorial, we are going to learn how to set the alignment of text in 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. Similarly, we can also set its text alignment by using the textAlign property. Syntax new fabric.Textbox(text: String, { textAlign : String }: Object) Parameters text − This parameter accepts a String which is the text string that we ...
Read MoreHow to find the original size of an Image using FabricJS?
In this tutorial, we are going to learn how to find the original size of an Image using FabricJS. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to find the original size of an Image, we use the getOriginalSize method. Syntax getOriginalSize(): Object Return Value The method returns an object containing the width and height of the original image in pixels: { ...
Read MoreHow to Enforce the type of the indexed members of a Typescript object
TypeScript is a strongly typed, object-oriented programming language built on JavaScript. One of its powerful features is the ability to enforce types of an object's indexed members using index signatures. This allows you to define the shape of objects with dynamic properties while maintaining type safety. An index signature specifies the types for both keys and values in an object. It's particularly useful when you need objects with unknown property names but known value types. Syntax interface ObjectType { [key: string]: ValueType; } // Or inline let objectName: { [key: string]: ...
Read MoreFinding smallest number that satisfies some conditions in JavaScript
We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n-digit number which is a multiple of all the elements specified in the array. If there exist no such n-digit element then we should return the smallest such element. For example: If the array is − const arr = [12, 4, 5, 10, 9] For both n = 2 and n = 3, we need to find the smallest number ...
Read MorePush specific elements to last in JavaScript
Suppose we have an array of objects like this: const arr = [ {flag: true, other: 1}, {flag: true, other: 2}, {flag: false, other: 3}, {flag: true, other: 4}, {flag: true, other: 5}, {flag: true, other: 6}, {flag: false, other: 7} ]; We are required to write a JavaScript function that takes in one such array and sorts it based on the following conditions: If arr.flag === false, the matching ...
Read MoreSorting an array objects by property having null value in JavaScript
When sorting arrays of objects in JavaScript, null values can disrupt the natural sorting order. This article shows how to sort objects by a property while ensuring null values appear at the end of the sorted array. Understanding the Problem When sorting objects by a numeric property, null values need special handling because they don't follow normal comparison rules. Our goal is to sort by the property value while pushing null values to the end. The Solution Approach We'll use a custom comparator function with JavaScript's sort() method. The key insight is to treat null values ...
Read MoreJavaScript - find distance between items on array
In JavaScript, finding the distance between items in an array involves calculating the difference between each element and all succeeding elements. This creates a matrix of distances that can be useful for various algorithms and data analysis. Suppose we have a sorted (increasing order) array of Numbers like this: const arr = [2, 5, 7, 8, 9]; We need to write a JavaScript function that takes in one such array. The function should construct a new subarray for each element of the input array containing the differences between that element and all succeeding elements. ...
Read MoreHow to shift each letter in the given string N places down in the alphabet in JavaScript?
In the given problem statement our aim is to shift every letter in the given string N places down in the alphabet with the help of JavaScript functionalities. This is also known as the Caesar cipher technique. Understanding the Problem The problem at hand is to shift each character of the given string N places down in the alphabet using JavaScript. We need to take a string as input and update it by shifting every letter N positions down in the alphabet. For example, if the letter ...
Read More