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
Finding intersection of arrays of intervals in JavaScript
JavaScript function that takes in two arrays, arr1 and arr2 of intervals which are pairwise disjoint and in sorted order. A closed interval [a, b] (with a
Read MoreReturning only odd number from array in JavaScript
JavaScript arrays often contain mixed data types, and finding specific patterns like the one odd number among evens (or vice versa) is a common programming challenge. This article demonstrates how to identify and return the single different element from an array. Problem Statement We need to write a JavaScript function that takes an array of integers as input. The array contains either all even numbers with one odd number, or all odd numbers with one even number. Our function should return this single different element. For example, if the input array is: const arr = ...
Read MoreHow to disable the centered scaling of Ellipse using FabricJS?
In this tutorial, we are going to learn how to disable the centered scaling of Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will have to create an instance of fabric.Ellipse 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.Ellipse({ centeredScaling: Boolean }: Object) Parameters options (optional) − ...
Read MoreHow to create a Textbox with wait cursor on moving objects using FabricJS?
In this article, we are going to create a Textbox with a wait cursor on moving objects using FabricJS. wait is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all scroll, crosshair, col-resize, row-resize etc which are reusing the native cursor underhood. The moveCursor property sets the style of the cursor when the object is moved around in the canvas. Syntax new fabric.Textbox(text: String, { moveCursor: String }: Object) Parameters ...
Read MoreHow to clear cache memory using JavaScript?
Cache memory, often known as cache, is a different memory system in a computer that stores frequently used data and instructions for a short period. While loading a website, the browser we are using will automatically cache some resources, such as images, scripts, and stylesheets, to be utilized again when the page is reloaded. This can shorten the time it takes for a website to load not only that but also it helps to lower the amount of data that has to be sent over the network. But this cache memory stored by the browser also has some disadvantages. If ...
Read MoreNon-composite numbers sum in an array in JavaScript
In JavaScript, you can calculate the sum of all prime numbers in an array by first checking each number for primality, then adding the prime numbers together. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Understanding Prime Numbers Prime numbers are numbers like 2, 3, 5, 7, 11, 13, etc. The number 1 is not considered prime, and 2 is the only even prime number. Creating a Prime Check Function First, we need a helper function to determine if a number is prime: ...
Read MoreCompute cartesian product of elements in an array in JavaScript
The Cartesian product of two sets (arrays) A and B, denoted A × B, is the set (array) of all ordered pairs (a, b) where a is in A and b is in B. In simpler terms, a cartesian product of two arrays is a permutation of all possible arrays of two elements whose first element belongs to the first array and the second element belongs to the second array. Example of Cartesian Product If the two arrays are: const arr1 = [1, 2, 3]; const arr2 = [4, 5]; Then their cartesian ...
Read MoreCompare Strings in JavaScript and return percentage of likeliness
We are required to write a JavaScript function that can compare two strings and return the percentage likeliness of how much they are alike. The percentage will be nothing but a measure of many characters the two strings have in common. If they are completely similar the output should be 100, and if they contain no common character at all, the output should be 0. Understanding the Algorithm This implementation uses the Levenshtein distance algorithm to calculate string similarity. The Levenshtein distance measures the minimum number of single-character edits (insertions, deletions, or substitutions) needed to change one ...
Read MoreSimilar string groups in JavaScript
Two strings are similar if we can swap exactly two characters at different positions to make them equal, or if they are already equal. Given an array of strings (all anagrams of each other), we need to find how many groups of similar strings exist. For example, "tars" and "rats" are similar (swap positions 0 and 2), and "rats" and "arts" are similar. This forms one group: {"tars", "rats", "arts"}. The string "star" forms its own group since it's not similar to any other string. Understanding Similarity Two strings are similar if: They are identical, or ...
Read MoreFinding squares in sorted order in JavaScript
We are required to write a JavaScript function that takes in an array of integers, arr, sorted in increasing order. Our function is supposed to return an array of the squares of each number, also sorted in increasing order. For example, if the input to the function is − const arr = [-2, -1, 1, 3, 6, 8]; Then the output should be − const output = [1, 1, 4, 9, 36, 64]; The Challenge Simply squaring and sorting would work, but it's inefficient. Since the original array is ...
Read More