Articles on Trending Technologies

Technical articles with clear explanations and examples

How to compare two arrays when the key is a string - JavaScript

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

Comparing two arrays in JavaScript can be tricky when the key is a string. String comparisons are case-sensitive and require special handling to ensure proper results. Fortunately, there are several methods you can use to compare two arrays when the key is a string in JavaScript. In this article, we'll discuss how to effectively compare two arrays with strings as keys using various approaches such as map(), includes(), intersection logic, and filter(). Strings in JavaScript are used to store and modify text. A string in JavaScript is defined as zero or more characters enclosed in quotations. Data that ...

Read More

Comparing array elements keeping count in mind in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 210 Views

Suppose, we have two arrays of literals that contain the same number of elements. We are supposed to write a function that checks whether or not the both arrays contain the same elements appearing for the same number of times. If the arrays fulfil this condition, we return true, false otherwise. We will create a copy of the second array, and start iterating over the first array. As we iterate, we will keep deleting the elements from the second array that are present in first array. If during iteration we encounter any element that isn't present in second ...

Read More

Compressing string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 6K+ Views

We are required to write a JavaScript function that takes in a string that might contain some continuous repeating characters. The function should compress the string like this − 'wwwaabbbb' -> 'w3a2b4' 'kkkkj' -> 'k4j' And if the length of the compressed string is greater than or equal to the original string we should return the original string. For example − 'aab' can be compressed to 'a2b1' but it increases its length to 4 so our function should return 'aab' How It Works The algorithm iterates through each character, counting consecutive ...

Read More

Hours and minutes from number of seconds using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 480 Views

We are required to write a JavaScript function that takes in the number of seconds and returns the number of hours and minutes contained in those seconds. Problem Statement Given a number of seconds, we need to convert it into a readable format showing hours and minutes. Input: 3601 seconds Expected Output: "1 hour(s) and 0 minute(s)" Solution Here's how we can convert seconds to hours and minutes: const seconds = 3601; const toTime = (seconds = 60) => { const hR = 3600; // 1 hour ...

Read More

All ways to divide array of strings into parts in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 341 Views

In JavaScript, dividing an array into two non-empty parts can be accomplished through various approaches. This tutorial explores different methods to generate all possible ways to split an array of strings into exactly two parts. Problem Statement We need to create a JavaScript function that takes an array of strings with at least two elements and returns all possible ways to divide it into two non-empty parts. For example, with the array ["az", "toto", "picaro", "zone", "kiwi"], we want to generate: (az) | (toto picaro zone kiwi) (az toto) | (picaro zone kiwi) ...

Read More

crypto.createHmac() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 3K+ Views

The crypto.createHmac() method creates and returns an HMAC (Hash-based Message Authentication Code) object in Node.js. This method uses a specified algorithm and secret key to generate cryptographic hashes for data integrity and authentication purposes. Syntax crypto.createHmac(algorithm, key, [options]) Parameters algorithm – The hashing algorithm to use (e.g., 'sha256', 'sha1', 'md5'). Input type is string. key – The secret key used for generating the cryptographic HMAC hash. Can be a string, Buffer, TypedArray, or DataView. options – Optional parameters for controlling stream ...

Read More

How to resize an object non-uniformly via corner points using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 986 Views

In this article, we are going to learn how to resize an object non-uniformly via corner points using FabricJS. In FabricJS, an object gets transformed proportionally when dragged from the corners. However, we can control this behavior by pressing the uniScaleKey. Syntax new fabric.Canvas(element: HTMLElement|String, { uniScaleKey: String }: Object) Parameters element − This parameter is the element itself which can be derived using Document.getElementById() or the id of the element itself. The FabricJS canvas will be initialized on this element. ...

Read More

JavaScript: Computing the average of an array after mapping each element to a value

Disha Verma
Disha Verma
Updated on 15-Mar-2026 1K+ Views

Computing the average of an array after mapping each element to a value in JavaScript can be done using several approaches including the forEach() loop, parseInt() method, reduce() method, and for...of loop. This article demonstrates how to calculate the average by summing all array elements and dividing by the array length. Given below are examples of arrays where we compute the average by summing values and dividing by the number of elements: Input: [1, 2, 3, 4, 5] Result: 3 Explanation: (1+2+3+4+5)/5 = 3 Input: [2, 4, 7, 9, 1, 3, 8] Result: 4.857142857142857 Explanation: (2+4+7+9+1+3+8)/7 ...

Read More

How to identify the type of a Line instance using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 237 Views

In this tutorial, we are going to learn about how to identify the type of a Line instance using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to identify the type of a Line instance, we use the isType method. Syntax ...

Read More

Understanding the find() method to search for a specific record in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 544 Views

The find() method searches through an array and returns the first element that matches a specified condition. It's perfect for locating specific records in arrays of objects. Syntax array.find(callback(element, index, array)) Parameters callback - Function to test each element element - Current element being processed index (optional) - Index of current element array (optional) - The array being searched Return Value Returns the first element that satisfies the condition, or undefined if no element is found. Example: Finding a Student Record var students = [ ...

Read More
Showing 15741–15750 of 61,297 articles
Advertisements