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
Unique number of occurrences of elements in an array in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the first and the only argument. The function should check whether all the integers that are present in the array appear for unique number of times or not. If they do, the function should return true, false otherwise. For example − If the input array is − const arr = [7, 5, 5, 8, 2, 4, 7]; Then the output should be − false because both the integers 7 and 5 appears ...
Read MoreSplitting number to contain continuous odd or even number using JavaScript
Problem We need to write a JavaScript function that takes a positive number and splits it into continuous segments of odd or even digits. The function should create a new segment whenever it encounters a digit with different parity (odd becomes even or even becomes odd). Example For the number 124579: 1 (odd) - starts first segment 2, 4 (even) - starts second segment 5, 7, 9 (odd) - starts third segment Solution Following is the code: const num = 124579; const splitDifferent = (num = 1) => { const ...
Read MoreHow to set the size of the controlling corners of Ellipse using FabricJS?
In this tutorial, we are going to learn how to set the size of the controlling corners of an Ellipse using FabricJS. The controlling corners of an object allow us to scale, stretch or change its position. We can customize our controlling corners in many ways such as adding a specific color to it, changing its size etc. We can change the size by using the cornerSize property. Syntax new fabric.Ellipse({ cornerSize: Number }: Object) Parameters options (optional) − This parameter is an ...
Read MoreHow to disable the selectability of Triangle using FabricJS?
In this tutorial, we are going to learn how to disable selectability 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. In order to modify an object, we have to select it in FabricJS. However, we can disable this behaviour by using the selectable property. Syntax new fabric.Triangle({ selectable: Boolean }: Object) Parameters ...
Read MoreHow to set the size of the controlling corners of Textbox using FabricJS?
In this tutorial, we are going to learn how to set the size of the controlling corners of a Textbox using FabricJS. The controlling corners of an object allow us to scale, stretch or change its position. We can customize our controlling corners in many ways such as adding a specific colour to it, changing its size etc. We can change the size by using the cornerSize property. Syntax new fabric.Textbox(text: String, { cornerSize: Number }: Object) Parameters text − This parameter accepts a String which is the text ...
Read MoreHow to exit editing state in IText using FabricJS?
In this tutorial, we are going to learn about how to exit editing state 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 automatically. This is not true for IText as ...
Read MoreHow to add an element horizontally in HTML page using JavaScript?
We can use the JavaScript method "createElement" to create a new element. Then, we can use the method "appendChild" to add the element to a parent element on the HTML page. To position the element horizontally, we can use CSS styles such as "display:inline-block" or "float:left/right" on the newly created element. Suppose a situation where we want to depict a graphical representation of a Linked List data structure. Every time the user clicks on a button, a new node, represented by a green circle in our case, should get prepended to the list of nodes horizontally. And the ...
Read MoreSort an array according to another array in JavaScript
When working with arrays in JavaScript, you may need to sort one array based on the order of elements in another array. This is useful when you have a reference array that defines the desired ordering. Suppose we have two arrays like these: const arr1 = [1, 3, 2, 4, 5, 6]; const arr2 = [1, 2, 5]; console.log("Original arr1:", arr1); console.log("Reference arr2:", arr2); Original arr1: [ 1, 3, 2, 4, 5, 6 ] Reference arr2: [ 1, 2, 5 ] We want to sort arr1 so that elements appearing in ...
Read MoreFinding the longest valid parentheses JavaScript
Given a string containing just the characters '(' and ')', we find the length of the longest valid (well-formed) parentheses substring. A set of parentheses qualifies to be a well-formed parentheses, if and only if, for each opening parentheses, it contains a closing parentheses. For example: '(())()' is a well-formed parentheses '())' is not a well-formed parentheses '()()()' is a well-formed parentheses Algorithm Approach The solution uses a stack-based approach to track invalid parentheses positions. We push indices of unmatched characters onto the stack, then calculate the longest valid substring between these invalid ...
Read MoreDestructively Sum all the digits of a number in JavaScript
Our main task is to write a function that destructively sums all the digits of a number using JavaScript. This approach modifies the original number during the calculation process by extracting each digit until none remain. Understanding the Problem The goal is to create a function that calculates the sum of all digits in a given number. The term "destructive" means the original number is modified during the process as we extract each digit. For example, given the number 123, we need to calculate: 1 + 2 + 3 = 6. Algorithm Step 1 − ...
Read More