Articles on Trending Technologies

Technical articles with clear explanations and examples

Converting degree to radian in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 609 Views

Converting degrees to radians is a common mathematical operation in JavaScript, especially when working with trigonometric functions or graphics programming. Understanding Radians The radian is the standard unit for measuring angles in mathematics. One complete circle equals 2π radians, which is equivalent to 360 degrees. This means π radians equals 180 degrees. The Conversion Formula To convert degrees to radians, multiply the degree value by π/180: radians = degrees × (π / 180) Method 1: Using the Standard Formula const degreeToRadian = (degree) => { const ...

Read More

Reversing negative and positive numbers in JavaScript

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

Problem We are required to write a JavaScript function that takes in a number and returns its reversed number. One thing that we should keep in mind is that numbers should preserve their sign; i.e., a negative number should still be negative when reversed. Example Following is the code − const num = -224; function reverseNumber(n) { let x = Math.abs(n) let y = 0 while (x > 0) { y = y * 10 + (x ...

Read More

Repeating each character number of times their one based index in a string using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 599 Views

We need to write a JavaScript function that takes a string of lowercase English letters and transforms it according to specific rules: each character should be repeated based on its 1-based index position, with the first letter capitalized, and character groups separated by dashes. Problem Statement Given a string of lowercase English alphabets, construct a new string where: Each character is repeated according to its 1-based index (1st char repeated 1 time, 2nd char repeated 2 times, etc.) The first letter of each repeated group is capitalized Different character groups are separated by dashes ('-') ...

Read More

How to display Material Chip View in React Native?

Shilpa S
Shilpa S
Updated on 15-Mar-2026 958 Views

To display chips in the UI, we are going to make use of React Native Paper Material Design. Chips are compact elements that represent input, attribute, or action. Installation Install react native paper as shown below − npm install react-native-paper Basic Syntax The basic chip component structure is as follows − Chip Name Properties The basic properties of chip are as follows − ...

Read More

How to add dashed stroke to a Rectangle using FabricJS?

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

In this tutorial, we are going to learn how to add a dashed stroke to a Rectangle 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. The strokeDashArray property allows us to specify a dash pattern for the object's stroke. Syntax new fabric.Rect({ strokeDashArray: Array }) Parameters Options (optional) − This parameter is an Object which provides additional ...

Read More

How to get the opacity of Text object using FabricJS?

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

In this tutorial, we are going to learn how to get the opacity 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 opacity of an object by using the getObjectOpacity method. Syntax getObjectOpacity() Example 1 Using the getObjectOpacity method Let's ...

Read More

How to manipulate DOM using a service worker in JavaScript?

Kalyan Mishra
Kalyan Mishra
Updated on 15-Mar-2026 1K+ Views

In this tutorial, you will learn about JavaScript DOM manipulation using a service worker. We'll explore how service workers can trigger DOM changes after successful registration and activation. DOM manipulation happens when we change the structure and elements of the document object model (DOM). We can modify DOM by adding, removing, changing, or modifying elements and their attributes. What is a Service Worker? Service workers act like proxy servers between web browsers and web servers. They run in the background and can intercept network requests, cache resources, and enable offline functionality. Service workers enhance existing websites by ...

Read More

Negative number digit sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 628 Views

We are required to write a JavaScript function that takes in a negative integer and returns the sum of its digits. Example Input For example: If the number is: -5456 Expected Output Then the output should be: 5+4+5+6 = 20 Using String Manipulation and Reduce The following approach converts the number to string, splits it into digits, and uses reduce to sum them: const num = -5456; const sumNum = num => { return String(num).split("").reduce((acc, val, ind) => { ...

Read More

Remove duplicates and map an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 657 Views

When working with arrays of objects, a common task is extracting unique values from a specific property. This tutorial shows how to remove duplicates and map an array to extract unique "name" values from objects. Problem Statement Suppose we have an array of objects like this: const arr = [ {id: 123, value: "value1", name: "Name1"}, {id: 124, value: "value2", name: "Name1"}, {id: 125, value: "value3", name: "Name2"}, {id: 126, value: "value4", name: "Name2"} ]; Note that some ...

Read More

Finding power set for a set in JavaScript Power Set

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 839 Views

The power set of a set S is the set of all of the subsets of S, including the empty set and S itself. The power set of set S is denoted as P(S). For example If S = {x, y, z}, the subsets are: { {}, {x}, {y}, {z}, {x, y}, {x, z}, {y, z}, {x, y, z} } We need ...

Read More
Showing 11891–11900 of 61,303 articles
Advertisements