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
Find all substrings combinations within arrays in JavaScript
We are required to write a JavaScript function that takes in an array of strings. The function should find all the substring and superstring combinations that exist in the array and return an array of those elements. For example − If the array is − const arr = ["abc", "abcd", "abcde", "xyz"]; Then the output should be − const output = ["abc", "abcd", "abcde"]; because the first two are the substring of the last one. How It Works The algorithm compares each string with every other string in the ...
Read MoreWays to get to a specific sum in JavaScript
Problem We are required to write a JavaScript function that takes in an array of integers, arr, as the first argument and a single integer, target, as the second argument. For each integer in the array, our function can either assign '+' or '-' to it. Our function should find out how many ways in total exist to assign '+', '-' to make the sum of integers of the array equal to the target sum. For example, if the input to the function is: const arr = [1, 1, 1, 1, 1]; const target = ...
Read MoreHow to use the debugger keyword in JavaScript?
Whenever an unexpected occurrence takes place in a JavaScript code, we need to debug it to check the cause. Debugging is a very important aspect of programming that lets you determine why a system or application behaves abnormally. It is a process of testing multiple times with different inputs and finding errors to reduce bugs from computer programs. In this article, we will be exploring the debugger keyword in JavaScript and how to use it. The debugger keyword in JavaScript is a common keyword used in debugging processes and variable inspection. When the debugger keyword is encountered and developer ...
Read MoreTweening and animating HTML5 and JavaScript properties with Tween.js
Tween.js is a JavaScript library that is mainly used when we want to tween or animate an HTML5 or JavaScript property. It can work standalone as well as when integrated with Easel.js. In this tutorial, we will learn how we can make use of Tween.js with the help of a few examples. Before we go on to the main example, let's first discuss a few simple tweens so that when we use them in the main example, you don't get overwhelmed. Simple Tween In this tween, we will tween the alpha property of the target from 0 ...
Read MoreHow to find the rotation matrix of a Polygon object using FabricJS?
We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. 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 rotation matrix, we use the _calcRotateMatrix() method. This method returns an Array with given values [cosA, sinA, -sinA, cosA, 0, 0] where A is the angle of rotation in degrees. Syntax _calcRotateMatrix(): Array Return Value ...
Read MoreHow a Polygon is different from a Polyline in FabricJS?
We can create a Polyline object by creating an instance of fabric.Polyline while fabric.Polygon can be used to create a Polygon instance. A polyline object can be characterised by a set of connected straight-line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. A polygon always connects the first point to the last to make a closed area while a polyline doesn't. This can be proved by the examples given below. Syntax new fabric.Polyline(points: Array, options: Object) new fabric.Polygon(points: Array, options: ...
Read MoreCreate array from JSON object JavaScript
In this article, we will learn to create an array from JSON data in JavaScript. JSON is a widely used format for storing and exchanging data. A common use case involves extracting specific data from a JSON object or array and converting it into a separate array for further processing. What is JSON Data? JSON (JavaScript Object Notation) is a lightweight data format commonly used to store and exchange data between a server and a client. It represents data as key-value pairs and is easy for both humans and machines to read and write. In JavaScript, JSON objects ...
Read MoreReturn a sorted array in lexicographical order in JavaScript
We are required to write a JavaScript function that takes two arrays, say arr1 and arr2. Our function should return a sorted array in lexicographical order of the strings of arr1 which are substrings of strings of arr2. How It Works The function iterates through arr1 and checks if each string is a substring of any string in arr2. If found, it adds the string to the result array and continues to the next string using a labeled continue statement. Example The code for this will be − const lexicographicalSort = (arr1 = [], ...
Read MoreHow to check two numbers are approximately equal in JavaScript?
In JavaScript, determining if two floating-point numbers are "approximately equal" is essential because of precision issues with decimal calculations. We compare the absolute difference between two numbers against a tolerance value called epsilon. Why Use Approximate Equality? Floating-point arithmetic can produce unexpected results: console.log(0.1 + 0.2); // 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // false 0.30000000000000004 false The Algorithm We calculate the absolute difference between two numbers and compare it with epsilon (tolerance). If the difference is less ...
Read MoreAuto-formatting Input Text Content with Cleave.js
Auto-formatting is one of those features that are hard to implement but at the same time increases the user experience a lot. There are different JavaScript libraries that one can use when they want to auto-format the input text content, but the most popular of them is Cleave.js. Cleave.js is a JavaScript library that is mainly used when we want to format the input text content and it works very smoothly. It is very lightweight and easy to get started with. In this tutorial, we will take a couple of examples to demonstrate how you can use Cleave.js to ...
Read More