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
Retrieving the decimal part only of a number in JavaScript
Precision and accuracy play vital roles in numerical computations, and in JavaScript programming, the ability to extract the decimal part of a number is a crucial skill. Whether it is for rounding, comparison, or further manipulation, retrieving only the decimal part of a number can significantly enhance the precision and control over calculations. Problem Statement Given a number in JavaScript, retrieve the decimal part only and return it as a separate number. Sample Input: num = 3.14159 Sample Output: ...
Read MoreFinding state after all collisions in JavaScript
Problem We are required to write a JavaScript function that takes in an array, arr, that represents the positions of different asteroids in a one-dimensional space. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Our function is supposed to find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet. Example Input ...
Read MoreHow to set the angle of skew on Y-axis of a Rectangle using FabricJS?
In this tutorial, we are going to learn how to set the angle of skew on the y-axis of 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. Our rectangle object can be customized in various ways like changing its dimensions, adding a background color or by changing the angle of skew on the Y-axis. We can do this by using the skewY ...
Read MoreHow to create a canvas with Line using FabricJS?
In this tutorial, we are going to learn about how to create a canvas with a Line object 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. Syntax new fabric.Line(points: Array, options: Object) Parameters ...
Read MoreHow to stop forEach() method in JavaScript?
In JavaScript, programmers can use the forEach() method to iterate through array elements. We can call a callback function, which we pass as a parameter of the forEach() method for every array element. Sometimes, we may need to stop the forEach() loop after executing the callback function for some elements. We can use the 'break' keyword with a normal loop to stop it: for(let i = 0; i < length; i++){ // code if(some condition){ break; } } However, we ...
Read MoreHow does Implicit coercion differ from Explicit coercion in JavaScript?
In this article, you will understand how implicit coercion differs from explicit coercion in JavaScript. An implicit coercion is an automatic conversion of values from one datatype to another that JavaScript performs automatically without programmer intervention. An explicit coercion is the deliberate conversion of data type using built-in functions or operators. Implicit Coercion JavaScript automatically converts data types when needed, especially in operations involving different types. let number = 5; let text = "10"; // JavaScript automatically converts number to string let result1 = number + text; console.log("5 + '10' =", result1, typeof result1); ...
Read MorePerforming the subtraction operation without the subtraction operator in JavaScript
We are required to write a JavaScript function that takes in two numbers and returns their difference but without using the (-) sign. This problem can be solved using bitwise operations. The key insight is that subtraction can be performed using XOR (^) and AND (&) operations combined with bit shifting. How It Works The algorithm uses these bitwise operations: XOR (^): Performs subtraction without handling borrows AND (&): Identifies positions where borrowing is needed Left shift ( { console.log(`Step ${step}: a=${a}, b=${b}`); if(b === 0){ console.log(`Result: ${a}`); return a; } const xor = a ^ b; const borrow = (~a & b)
Read MoreConverting a string to NATO phonetic alphabets in JavaScript
The NATO phonetic alphabet is a standardized set of code words used to represent letters of the alphabet in radio and telephone communications. This tutorial shows how to convert any string into NATO phonetic alphabet representation using JavaScript. NATO Phonetic Alphabet The 26 code words are: Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Juliett, Kilo, Lima, Mike, November, Oscar, Papa, Quebec, Romeo, Sierra, Tango, Uniform, Victor, Whiskey, X-ray, Yankee, Zulu. Implementation Here's a complete function that converts a string to NATO phonetic alphabet: const str = 'this is simple string'; const ...
Read MoreReducing array elements to all odds in JavaScript
We need to write a JavaScript function that transforms an array by converting all numbers to odd values. The transformation rules are: If the number is odd, leave it unchanged. If the number is even, subtract 1 from it to make it odd. This ensures all elements in the resulting array are odd numbers. Example Here's how to implement this transformation: const arr = [5, 23, 6, 3, 66, 12, 8]; const reduceToOdd = (arr = []) => { const res = []; ...
Read MoreHow to set the colour of controlling corners of a Triangle using FabricJS?
In this tutorial, we are going to set the colour of the controlling corners of Triangle using FabricJS. The cornerColor property allows us to manipulate the colour of the controlling corners when the object is active. Syntax new fabric.Triangle({ cornerColor: String }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our triangle. Using this parameter, properties such as colour, cursor, stroke width, and a lot of other properties can be changed related to the object of ...
Read More