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 power set for a set in JavaScript Power Set
The power set of a set S is the set of all of the subsets of S, including the empty set and S itself. The power set of set S is denoted as P(S). For example If S = {x, y, z}, the subsets are: { {}, {x}, {y}, {z}, {x, y}, {x, z}, {y, z}, {x, y, z} } We need ...
Read MoreReversing consonants only from a string in JavaScript
We are required to write a JavaScript function that takes in a string of lowercase English alphabets as the only argument. The function should construct a new string in which the order of consonants is reversed and the vowels hold their relative positions. Problem Statement For example, if the input to the function is: const str = 'somestring'; Then the output should be: const output = 'gomenrtiss'; In this example, consonants 's', 'm', 't', 'r', 'n', 'g' are reversed to 'g', 'n', 'r', 't', 'm', 's', while vowels 'o', ...
Read MoreFinding array number that have no matching positive or negative number in the array using JavaScript
We need to write a JavaScript function that finds a number in an array that doesn't have its positive or negative counterpart. For example, in an array containing both 1 and -1, both 2 and -2, but only 3 (without -3), we should return 3. Problem Given an array of integers where each number has its negative or positive complement, except for exactly one number, our function should find and return that unpaired number. Example Input Consider the array [1, -1, 2, -2, 3]. Here, 1 has -1, 2 has -2, but 3 has no -3, ...
Read MoreJavaScript: How to filter out Non-Unique Values from an Array?
To filter out non-unique values from an array in JavaScript, you can use the filter() method, a for loop, the Set and filter() method, and the reduce() method. In this article, we will filter out non-unique values and return an array that only contains unique non-repeating elements. Arrays are data structures used to store data in a structured format. We can store the data in an array and retrieve them using their indexes. These indexes serve as a key for these values. Table of Content Filtering non-unique values from an array can be done in the following ways: ...
Read MoreHow to add shadow to a Rectangle using FabricJS?
In this tutorial, we are going to learn how to add a shadow to a Rectangle using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. Our rectangle 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 rectangle by using the shadow property. Syntax new fabric.Rect({ shadow: fabric.Shadow }) Parameters ...
Read MoreHow to get the scaled height of Text using FabricJS?
In this tutorial, we are going to learn how to get the scaled height of 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, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can also find the object's scaled height by using the getScaledHeight method. Syntax getScaledHeight() Example 1: Using the getScaledHeight method Let's see ...
Read MoreWhat are decorators and how are they used in JavaScript?
In this tutorial, you will learn about JavaScript decorators and get to know about their inner workings and uses. What are Decorators in JavaScript? The word decorator means combining a set of code or program with another or can be said as wrapping a function with another function to extend the functionality or working of the function. Decorator can also be called as decorator function. Developers have been using this decorator term in other languages like Python, C# and now JavaScript has also introduced the decorator pattern. Function Decorators In JavaScript functions behave like objects ...
Read MoreOmitting false values while constructing string in JavaScript
We have an array that contains some string values as well as some false values like null, undefined, 0, and empty strings. We need to write a JavaScript function that takes this array and returns a string constructed by joining values while omitting all falsy values. Understanding Falsy Values In JavaScript, falsy values include: false, 0, "", null, undefined, and NaN. These evaluate to false in boolean contexts. Method 1: Using reduce() with Logical OR The logical OR operator (||) returns the right operand when the left is falsy: const arr = ["Here", ...
Read MoreCapitalize a word and replace spaces with underscore - JavaScript?
In JavaScript, you can capitalize words and replace spaces with underscores using various string methods. This transformation is commonly needed for creating identifiers, constants, or formatted text. let input = "tutorials point"; console.log("Input:", input); // Expected output: "Tutorials_Point" Input: tutorials point Let's explore different methods to achieve this transformation in JavaScript. Using replace() Method The replace() method searches for a specified pattern in a string and replaces it with a new value. It accepts regular expressions for complex pattern matching. Syntax string.replace(searchValue, newValue) Example 1: Basic ...
Read MoreFilter array of objects whose properties contains a value in JavaScript
Filtering an array of objects based on property values is a common task in JavaScript. This technique allows you to search through all properties of objects to find matches based on a keyword. Sample Data Let's start with an array of objects containing user information: const arr = [{ name: 'Paul', country: 'Canada', }, { name: 'Lea', country: 'Italy', }, { name: 'John', country: 'Italy', }]; The Problem We need to filter objects where any ...
Read More