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
Writing table of number in array in JavaScript
We are required to write a JavaScript function that takes in two numbers, say m and n, and it returns an array of first n multiples of m. Therefore, let's write the code for this function − Example The code for this will be − const num1 = 4; const num2 = 6; const multiples = (num1, num2) => { const res = []; for(let i = num1; i { return Array.from({length: count}, (_, index) => base * (index + 1)); }; console.log(generateTable(7, 5)); console.log(generateTable(3, 8)); [ 7, 14, 21, 28, 35 ] [ 3, 6, 9, 12, 15, 18, 21, 24 ] Using a Simple For Loop Here's another straightforward approach using a basic for loop: function createMultiplicationTable(number, count) { const table = []; for (let i = 1; i
Read MoreRandom whole number between two integers JavaScript
In JavaScript, generating a random whole number between two integers is a common task that requires combining Math.random() with Math.floor() to ensure we get integers within the specified range. Understanding the Problem We need to create a function that returns a random integer between two given numbers (inclusive). For example, if we want a random number between 1 and 5, the possible outputs are: 1, 2, 3, 4, or 5. The Math.random() Method Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive). We need to transform this to get integers in our desired ...
Read MoreFind the largest palindrome number made from the product of two n digit numbers in JavaScript
In this problem, we need to find the largest palindrome number that can be created by multiplying two n-digit numbers using JavaScript. We'll implement two functions: one to find the largest palindrome product and another to check if a number is palindromic. What are Palindrome Numbers? A palindrome number reads the same forwards and backwards. Examples include 44, 121, 202, 404, and 909. When reversed, these numbers remain identical to their original form. Understanding the Problem We need to find the largest possible palindrome that results from multiplying two n-digit numbers. For example, with 2-digit numbers ...
Read MoreFinding the length of the diagonal of a cuboid using JavaScript
We need to write a JavaScript function that calculates the diagonal length of a cuboid (rectangular box) given its length, width, and height dimensions. Problem We are required to write a JavaScript function that takes in the length, width and height of a cuboid and return the length of its diagonal. Formula The space diagonal of a cuboid is calculated using the 3D Pythagorean theorem: diagonal = √(length² + width² + height²) Example Following is the code: const height = 10; const width = 12; const length = 15; ...
Read MoreHow to disable the centered scaling of Circle using FabricJS?
In this tutorial, we are going to learn how to disable the centered scaling of 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. When being scaled via controls, assigning a true value to the centeredScaling property, uses the center as the object's origin of transformation. Syntax new fabric.Circle({ centeredScaling: Boolean }: Object) Parameters options (optional) − ...
Read MoreHow to add shadow to a Triangle using FabricJS?
In this tutorial, we are going to learn how to add a shadow to 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. Our triangle object can be customized in various ways like changing its dimensions, adding a background color or even adding a shadow to it. We can add a shadow to the triangle by using the shadow property. Syntax new fabric.Triangle({ shadow : fabric.Shadow }: Object) ...
Read MoreHow to lock the vertical scaling of Textbox using FabricJS?
In this tutorial, we are going to learn how to lock the vertical scaling of a Textbox using FabricJS. Just as we can specify the position, colour, opacity and dimension of a textbox object in the canvas, we can also specify whether we want to stop scaling an object vertically. This can be done by using the lockScalingY property. Syntax new fabric.Textbox(text: String, { lockScalingY : Boolean }: Object) Parameters text − This parameter accepts a String which is the text string that we want to display inside our ...
Read MoreHow to center an object vertically with respect to current viewport of canvas in IText using FabricJS?
In this tutorial, we are going to learn about how to center an object vertically with respect to current viewport of canvas in IText 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 ...
Read MoreHow to solve too many try catch in Typescript?
We can use the try-catch statements to handle errors in TypeScript. Sometimes, we require adding more than one try-catch block in the code to handle multiple errors. When we add multiple try-catch statements in the code, the code becomes unreadable, and it becomes a headache for developers to refactor. In this tutorial, we will learn to convert too many try-catch blocks into a single try-catch block which can manage multiple errors. Syntax Users can follow the syntax below to use the single try-catch block in TypeScript. try { throw new Error("error_message"); ...
Read MoreJavascript Program to Count 1's in a sorted binary array
We have two approaches to count 1's in a sorted binary array. The first one is to iterate through the array and count the 1's. The second approach is to use a binary search algorithm to find the first occurrence of 1 in the array. It is important to note that in order to use these approaches, the array must be sorted. In this article, we will discuss a JavaScript program to count the number of 1's in a sorted binary array. We will also look at some edge cases and optimization techniques to make the program more ...
Read More