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
Remove duplicates from array with URL values in JavaScript
Suppose, we have an array of objects like this − const arr = [ { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello-how-are-you', id: ...
Read MoreMost efficient method to groupby on an array of objects - JavaScript
Grouping arrays of objects is a common task in JavaScript data processing. We'll explore efficient methods to group objects by single or multiple properties and aggregate values. Sample Data Let's start with an array of objects representing project phases, steps, and tasks: const arr = [ { Phase: "Phase 1", Step: "Step 1", Task: "Task 1", Value: "5" }, { Phase: "Phase 1", Step: "Step 1", Task: "Task 2", Value: "10" }, { Phase: "Phase 1", Step: "Step 2", Task: "Task 1", Value: "15" ...
Read MoreFinding the product of array elements with reduce() in JavaScript
We are required to write a JavaScript function that takes in an array and finds the product of all its elements using the reduce() method. Understanding reduce() for Products The reduce() method executes a reducer function on each array element, accumulating results into a single value. For multiplication, we start with an initial value of 1 and multiply each element. Syntax array.reduce((accumulator, currentValue) => { return accumulator * currentValue; }, 1); Example: Basic Product Calculation const arr = [3, 1, 4, 1, 2, -2, -1]; const ...
Read MoreHow to crop the top offset in a cloned image using FabricJS?
In this tutorial, we are going to learn how to crop the top offset in a cloned image using FabricJS. We can create an Image object by creating an instance of fabric.Image. 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 crop the top offset in a cloned image, we use the top property. Syntax cloneAsImage( callback: function, { top: Number}: Object): fabric.Object Parameters callback (optional) − This parameter is a function which ...
Read MoreGenerating combinations from n arrays with m elements in JavaScript
We are required to write a JavaScript function that generates combinations from n number of arrays with m number of elements in them. For example, consider this data: const arr = [ [0, 1], [0, 1, 2, 3], [0, 1, 2] ] We have 3 sub-arrays with different numbers of elements. What we want to do is get all combinations by selecting one item from each array. Understanding the Problem The goal is to generate a Cartesian product of multiple arrays. For the example ...
Read MoreGet the smallest array from an array of arrays in JavaScript
When working with nested arrays in JavaScript, you might need to find the smallest subarray based on the number of elements. This is useful for data processing, filtering operations, or when you need to identify the shortest path or sequence. Suppose we have a nested array of arrays like this: const arr = [ ["LEFT", "RIGHT", "RIGHT", "BOTTOM", "TOP"], ["RIGHT", "LEFT", "TOP"], ["TOP", "LEFT"] ]; console.log("Original array:", arr); Original array: [ [ 'LEFT', 'RIGHT', 'RIGHT', 'BOTTOM', 'TOP' ], ...
Read MoreEncoding decimal to factorial and back in JavaScript
The factorial number system uses factorials as bases instead of powers. Each digit position represents a factorial base, where the rightmost digit is base 0!, the next is base 1!, then base 2!, and so on. How Factorial Encoding Works In factorial representation, the nth digit from the right can range from 0 to n. For example: Position 0 (rightmost): 0 to 0, multiplied by 0! = 1 Position 1: 0 to 1, multiplied by 1! = 1 Position 2: 0 to 2, multiplied by 2! = ...
Read MoreHow to change an element's class with JavaScript?
In JavaScript, you can change an element's class using several methods. The most common approaches are using the className property for complete replacement and classList methods for more flexible manipulation. How to change the element's class using className property How to toggle between classes using className and classList Using className Property The className property allows you to get or set the entire class attribute of an element. When you assign a new value, it replaces all existing classes. Example ...
Read MoreHow to find a nearest higher number from a specific set of numbers: JavaScript ?
We have a set of numbers and our requirement is to find the same or the nearest higher number key to a specific number provided as the input to the function. The set of numbers is defined as: const numbers = { A: 107, B: 112, C: 117, D: 127, E: 132, F: 140, G: 117, H: 127, I: 132, J: 132, K: 140, ...
Read MoreReturning the highest value from an array in JavaScript
We are required to write a JavaScript function that takes in an array of Numbers. Our function should iterate through the array and pick the greatest (largest) element from the array and return that element. Using a Custom Loop Function Here's a manual approach that iterates through the array to find the maximum value: const arr = [5, 3, 20, 15, 7]; const findGreatest = (arr = []) => { let greatest = -Infinity; if (!arr?.length) { return null; ...
Read More