Articles on Trending Technologies

Technical articles with clear explanations and examples

Length of shortest unsorted array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 220 Views

We are required to write a JavaScript function that takes in an array of numbers and finds the length of the shortest continuous subarray that, when sorted, makes the entire array sorted in ascending order. Our function needs to find the length of one continuous subarray such that if we only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. Problem Example For example, if the input array is: const arr = [3, 7, 5, 9, 11, 10, 16]; console.log("Original array:", arr); Original array: ...

Read More

How to apply function against an accumulator and each key of object in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 534 Views

In JavaScript, we can use the reduce() method to apply a function against an accumulator and each element of an array (from left to right). This method is particularly useful when working with arrays of objects where we need to process each key-value pair. The reduce() method is called on a given array and takes a callback function as its first argument. Please refer to Array reduce() for more details. Syntax array.reduce(callback[, initialValue]) Parameters callback − Function to execute on each value in the array. ...

Read More

Fabric.js – How to check if an Image object is fully contained within the area of another object?

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

In this tutorial, we are going to learn how to check if an Image object is fully contained within the area of another object 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 check if an Image object is fully contained within the area of another object, we use the isContainedWithinObject method. Syntax isContainedWithinObject(other: Object, absolute: Boolean, calculate: Boolean): Boolean Parameters other ...

Read More

Why do we Use JavaScript in HTML?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 2K+ Views

JavaScript transforms static HTML pages into dynamic, interactive websites. When a website displays timely content updates, interactive maps, animated visuals, or responsive user interfaces, JavaScript is the technology making it happen. As a scripting language, JavaScript adds advanced functionality to websites and represents the third essential layer of modern web development. The Three Layers of Web Development Modern web pages are built using three complementary technologies that work together: HTML (Structure): The markup language that defines the content structure and meaning. HTML creates paragraphs, headings, lists, and embeds images and videos into web ...

Read More

How to add a clipping area on a Polygon using FabricJS?

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

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. A clipping path restricts the area to which fill or stroke is applied in a Polygon object. Therefore, the parts of the polygon which lie outside the clipping path, will not be drawn. In order to add a clipping area we use the clipPath property. ...

Read More

Fetch specific values from array of objects in JavaScript?

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

Fetching specific values from an array of objects is a common JavaScript task. This article demonstrates multiple approaches to filter and extract data based on specific criteria. Sample Data Let's start with an array of employee objects: const details = [ { employeeFirstName: "John", employeeLastName: "Doe" }, { employeeFirstName: "David", employeeLastName: "Miller" ...

Read More

Filtering out the non-unique value to appear only once in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 243 Views

We have an array that contains some duplicate values appearing multiple times. We need to extract only the elements that appear more than once in the array, but show each duplicate element only once in the result. const arr = [1, 4, 3, 3, 1, 3, 2, 4, 2, 1, 4, 4]; console.log("Original array:", arr); Original array: [1, 4, 3, 3, 1, 3, 2, 4, 2, 1, 4, 4] We need to write a JavaScript function that filters out elements that appear multiple times and returns each duplicate element only once. For ...

Read More

Merge JSON array date based JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 794 Views

When working with JSON arrays containing objects with date properties, you often need to merge objects that share the same date. This is common when combining data from different sources or consolidating time-series data. Suppose we have the following array of objects: const arr = [ { "date": "2010-01-01", "price": 30 }, { "date": "2010-02-01", ...

Read More

Find what numbers were pressed to get the word (opposite of phone number digit problem) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 200 Views

The mapping of the numerals to alphabets in the old keypad type phones used to be like this: const mapping = { 1: [], 2: ['a', 'b', 'c'], 3: ['d', 'e', 'f'], 4: ['g', 'h', 'i'], 5: ['j', 'k', 'l'], 6: ['m', 'n', 'o'], 7: ['p', 'q', 'r', 's'], 8: ['t', 'u', 'v'], 9: ['w', 'x', 'y', 'z'] }; console.log(mapping); { '1': [], '2': [ 'a', 'b', 'c' ], '3': ...

Read More

Counting the number of 1s upto n in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 312 Views

Counting the number of 1s from 1 to n is a common algorithmic problem in JavaScript. We need to count how many times the digit "1" appears in all positive integers up to and including n. For example, if n = 31, the digit "1" appears in: 1, 10, 11 (twice), 12, 13, 14, 15, 16, 17, 18, 19, 21, 31. That's a total of 14 occurrences. Problem Analysis The challenge is to efficiently count digit occurrences without iterating through every number. We can solve this using digit-by-digit analysis or a simpler brute force approach. Method ...

Read More
Showing 11861–11870 of 61,303 articles
Advertisements