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
Read by key and parse as JSON in JavaScript
In JavaScript, you often need to group JSON data by specific keys and transform the structure. This tutorial shows how to read data by key values and reorganize it into a grouped JSON format. Problem Statement Given a JSON array with nested data, we want to group items by a specific key (like "W") and create a new structure where each group becomes a separate object. Starting with this data structure: const arr = [{ "data": [ { "W": 1, "A1": "123" }, ...
Read MoreMaximum decreasing adjacent elements in JavaScript
In JavaScript, finding the maximum number of decreasing adjacent elements means identifying the longest consecutive sequence where each element is smaller than the previous one. This is essentially finding the longest decreasing subarray. Understanding the Problem We need to find the maximum count of consecutive decreasing pairs in an array. For example, in array [5, 4, 3, 2, 1], we have 4 decreasing pairs: (5, 4), (4, 3), (3, 2), and (2, 1). Finding Decreasing Adjacent Elements 5 arr[0] ...
Read MoreGenerating desired combinations in JavaScript
In JavaScript, generating combinations that sum to a target value is a common programming challenge. This problem involves finding all unique combinations of integers from 1 to 9 with a specific length that sum to a target value. Understanding the Problem We need to generate combinations where: m represents the size of each combination n represents the target sum Each combination uses unique numbers from 1 to 9 For example, if m = 3 and n = 9, valid combinations include [1, 2, 6], [1, 3, 5], and [2, ...
Read MoreIntersection of three sorted arrays in JavaScript
We are required to write a JavaScript function that takes in three arrays of integers all sorted in an increasing order. The function should then construct and return an array that contains only those elements that are present in all three arrays. For example, if the input arrays are: const arr1 = [4, 7, 8, 11, 13, 15, 17]; const arr2 = [1, 3, 4, 13, 18]; const arr3 = [2, 4, 7, 8, 9, 10, 13]; Then the output should be: const output = [4, 13]; Three-Pointer Approach Since ...
Read MoreMap Sum Pairs in JavaScript
The MapSum data structure allows you to store key-value pairs and efficiently calculate the sum of all values whose keys start with a given prefix. This problem is commonly solved using a Trie (prefix tree) data structure. Problem Overview We need to implement a MapSum class with two methods: insert(key, value): Stores a key-value pair. If the key already exists, it updates the value. sum(prefix): Returns the sum of all values whose keys start with the given prefix. Solution Using Trie Structure The solution uses a Trie where each node can store a ...
Read MoreHow to set the position of a Triangle from top using FabricJS?
In this tutorial, we will learn how to set the position of a triangle from the top using FabricJS. The top property allows us to manipulate the vertical position of the triangle object on the canvas. By default, when no top value is specified, the triangle is positioned at the top edge of the canvas. Syntax new fabric.Triangle({ top: Number }) Parameters Options (optional) − This parameter is ...
Read MoreHow to create a function that invokes each provided function using JavaScript?
In JavaScript, functions are first-class objects, which means they can be passed as arguments to other functions. This powerful feature enables creating functions that can invoke multiple other functions systematically. The "invoke-each" pattern creates a function that invokes each provided function with the same set of arguments. This pattern is particularly useful for executing multiple operations with shared data. Why Use the Invoke-Each Pattern? The invoke-each pattern serves several important purposes: Abstraction: It hides the complexity of invoking multiple functions, making code cleaner and more maintainable. Batch Operations: Execute ...
Read MoreHow to change the font weight of Text using FabricJS?
In this tutorial, we are going to see how to change the font weight 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. Font weight refers to the value which determines how bold or light our text will appear. Syntax new fabric.Text(text: String , { fontWeight: Number|String }: Object) ...
Read MoreHow to access the first value of an object using JavaScript?
In this article, you will understand how to access the first value of an object using JavaScript. The first value of an object refers to the value of the first property in the object. JavaScript provides several methods to retrieve this value, depending on whether you're working with objects or arrays. Using Object.values() for Objects The Object.values() method returns an array of all enumerable property values, making it easy to access the first value. const inputObject = {1: 'JavaScript', 2: 'Python', 3: 'HTML'}; console.log("A key-value pair object is defined and its values are: ", inputObject); ...
Read MoreWhy addEventListener to 'select' element does not work in JavaScript?
When working with HTML elements in JavaScript, developers often encounter issues with event listeners not working as expected. The key is understanding which events work with select elements and how to properly attach them using querySelector() and addEventListener(). Understanding the Change Event The element fires a change event when the user selects a different option. Unlike input events that fire continuously, the change event only fires when the selection is complete. Required Methods The addEventListener() Method - Registers an event handler for a specified event type on an element. target.addEventListener(event, function, useCapture) ...
Read More