Articles on Trending Technologies

Technical articles with clear explanations and examples

Sort array by month-year JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 774 Views

Suppose, we have an array that contains dates in MM-YYYY format like this − const arr = ["1-2016", "7-2015", "7-2016", "3-2016", "8-2016", "2-2016", "6-2016", "8-2015", "5-2016", "4-2016", "9-2015", "10-2015", "11-2015", "12-2015"]; console.log("Original array:", arr); Original array: [ '1-2016', '7-2015', '7-2016', '3-2016', '8-2016', '2-2016', '6-2016', '8-2015', '5-2016', '4-2016', '9-2015', '10-2015', '11-2015', '12-2015' ] We are required to write a JavaScript function that takes in one such array and sorts it such that the dates in the ...

Read More

Interpolation Search in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 764 Views

Interpolation search is an efficient searching algorithm for sorted arrays with uniformly distributed values. Unlike binary search, which always checks the middle element, interpolation search estimates where the target value is likely to be found based on its value relative to the array bounds. How Interpolation Search Works The algorithm uses a mathematical formula to estimate the position of the target element: pos = lo + ((target - arr[lo]) * (hi - lo) / (arr[hi] - arr[lo])) This formula returns a higher position when the target is closer to the end of the array, ...

Read More

Checking if a number is a valid power of 4 in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 409 Views

We are required to write a JavaScript function that takes in a single integer, num, as the only argument. Our function should check whether this number is a valid power of 4 or not. If it is a power of 4, we should return true, false otherwise. For example, if the input to the function is: const num1 = 2356; const num2 = 16; Then the output should be: const output1 = false; const output2 = true; Understanding Powers of 4 Powers of 4 are numbers that can be expressed ...

Read More

Returning an array containing last n even numbers from input array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 228 Views

Problem We are required to write a JavaScript function that takes in an array of numbers as the first argument and a number as the second argument. Our function should pick and return an array of last n even numbers present in the input array. Example Following is the code − const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const num = 3; const pickEvens = (arr = [], num = 1) => { const res = []; for(let index = ...

Read More

crypto.randomFill() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 311 Views

The crypto.randomFill() method in Node.js fills an existing buffer with cryptographically strong random data. Unlike crypto.randomBytes() which creates a new buffer, randomFill() fills a provided buffer with random data. Syntax crypto.randomFill(buffer, [offset], [size], [callback]) Parameters buffer – The buffer to be filled. Supported types: Buffer, TypedArray, ArrayBuffer, DataView. Maximum size is 2**31-1. offset – Starting position for filling (optional). Default is 0. size – Number of bytes to fill from the offset (optional). Default is buffer.length - offset. callback – Function called when operation completes or errors occur (optional). Example: Basic ...

Read More

JavaScript: How to Check if a String is a Literal or an Object?

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

In this article, we will explore how JavaScript strings can exist as literals or objects, and learn methods to distinguish between them. In JavaScript, strings can exist in two forms: String Literal: Created using quotes (', ", or `) String Object: Created explicitly using the String constructor with new String("text") Understanding String Literals vs String Objects String literals are primitive values, while String objects are wrapper objects around the primitive string value. This distinction affects how they behave with certain operators and methods. Using typeof to Check String ...

Read More

How to create a canvas with Rectangle using FabricJS?

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

In this tutorial, we are going to learn how to create a canvas with a Rectangle object 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. Syntax new fabric.Rect({ width: Number, height: Number }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this parameter, properties such as colour, ...

Read More

How to get the style of current selection in Text using FabricJS?

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

In this tutorial, we are going to learn how to get the style of current selection 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 style of current selection by using the getSelectionStyles method. Syntax getSelectionStyles(startIndexopt, endIndexopt, completeopt) Parameters ...

Read More

Position Tooltips and Popovers using Popper.js

Mukul Latiyan
Mukul Latiyan
Updated on 15-Mar-2026 3K+ Views

Popper.js is a JavaScript library used to build and manage poppers, tooltips, and popovers in web applications. It provides powerful positioning capabilities that automatically handle edge detection and placement calculations. In this tutorial, we'll create an interactive tooltip using Popper.js. Setting Up Popper.js First, include Popper.js in your project. We'll use the CDN version for simplicity: Basic HTML Structure Create a button element (reference) and a tooltip element (popper). The tooltip will be positioned relative to the button: Popper Tooltip Example ...

Read More

Finding two golden numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 205 Views

We are required to write a JavaScript function that takes in two numbers representing a sum and product, and returns two numbers whose sum equals the first parameter and product equals the second parameter. If no such numbers exist, the function should return false. Problem Understanding Given sum s and product p, we need to find two numbers x and y such that: x + y = s x × y = p Mathematical Approach This is essentially solving a quadratic equation. If x + y = s and x × y = p, ...

Read More
Showing 15981–15990 of 61,297 articles
Advertisements