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
Setting a default variable value to undefined in a function - JavaScript?
The task we are going to perform in this article is setting a default variable value to undefined in a function. Before we jump into the article, let's understand what are functions in JavaScript. One of the core components of JavaScript are functions. In JavaScript, a function is comparable to a procedure-a collection of statements that carry out an action or compute a value. However, in order for a process to be considered a function, it must accept an input and produce an output with an evident connection between the input and the result. Let's see how to ...
Read MoreHow to make Ulam number sequence in JavaScript?
A mathematician Ulam proposed generating a sequence of numbers from any positive integer n (n>0) as follows: If n is 1, it will stop. if n is even, the next number is n/2. if n is odd, the next number is 3 * n + 1. continue with the process until reaching 1. This sequence is also known as the Collatz conjecture or 3n+1 problem. It's conjectured that all positive integers eventually reach 1 following these rules. Example Sequences Here are some examples for the first few integers: 2→1 3→10→5→16→8→4→2→1 4→2→1 6→3→10→5→16→8→4→2→1 ...
Read MoreJSON group object in JavaScript
In JavaScript, grouping JSON objects means organizing data by common properties or categories. This is useful for data analysis, filtering, and creating structured reports from collections of objects. What is JSON? JSON (JavaScript Object Notation) is a lightweight data format for transferring data between devices. JSON objects use key-value pairs where keys are strings and values can be strings, numbers, booleans, arrays, or nested objects. For example: {"name": "Alice", "age": 25}. const jsonData = [ { team: 'TeamA', score: 20 }, { ...
Read MoreHow to split sentence into blocks of fixed length without breaking words in JavaScript
In JavaScript, splitting a sentence into blocks of fixed length while keeping words intact requires careful handling of word boundaries. This ensures readability by avoiding broken words across blocks. Understanding the Problem We need to split a sentence into chunks of a specified maximum length without breaking words. Each block should contain complete words only, and if adding a word would exceed the length limit, that word starts a new block. For example, with the sentence "You are reading this article on Tutorials point website" and block length 15, the output should be: ['You are ...
Read MoreValidating a square in a 2-D plane in JavaScript
We are required to write a JavaScript function that takes in four arguments. The four arguments will all be arrays of exactly two numbers representing the coordinates of four vertices of a quadrilateral or any figure (closed or unclosed) on a plane. The task of our function is to determine whether or not the four vertices form a square. If they do form a square, we should return true, false otherwise. Understanding the Problem A square has specific properties: All four sides are equal in length All four angles ...
Read MoreTotal number of longest increasing sequences in JavaScript
Finding the total number of longest increasing subsequences (LIS) is a dynamic programming problem. We need to find all subsequences with the maximum possible length where each element is greater than the previous one. Problem We are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument. Our function is required to find the number of longest increasing subsequences (contiguous or non-contiguous). For example, if the input to the function is: const arr = [2, 4, 6, 5, 8]; The output ...
Read MoreHow does asynchronous code work in JavaScript?
In this article, we will be exploring how async code actually works in JavaScript, how it is initialized, and how it is executed and called. But before moving on let's look at what is synchronous code and how it is different from asynchronous code. Synchronous Code − Code executes line by line in order. Each operation must complete before the next one starts. The program waits for each task to finish. Asynchronous Code − ...
Read MoreHow to set the colour of controlling corners of a Rectangle using FabricJS?
In this tutorial, we are going to set the colour of the controlling corners of Rectangle using FabricJS. The cornerColor property allows us to manipulate the colour of the controlling corners when the object is active. Syntax new fabric.Rect({ cornerColor: String }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this parameter, properties such as colour, cursor, stroke width and a lot of other properties can be changed related to the object of ...
Read MoreHow to get an object containing parameters of current URL in JavaScript?
JavaScript provides several ways to extract URL parameters from the current page or any URL. This is useful for handling query strings, routing, and dynamic content based on URL parameters. Using the Location Object The easiest way to get information about the current URL is to use the Location object. This object is a property of the window object and contains information about the current URL. // Get the entire URL var ...
Read MoreHow to compute the height of a character at given position in Text using FabricJS?
In this tutorial, we are going to learn how to compute the height of a line at a specific line index in Text 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, and line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can also compute the height of a line at a required line index by using the getHeightOfLine method. Syntax ...
Read More