We need to write a JavaScript function that takes an array of positive integers, joins them to form a single number, adds 1 to that number, and returns the result as an array of digits. Problem Statement Given an array of positive integers, we need to: Join the digits to form a single number Add 1 to that number Return the result as an array of individual digits For example, if the input array is [6, 7, 3, 9], it represents the number 6739. Adding 1 gives us 6740, which should be returned as [6, ... Read More
In this tutorial, we are going to learn how we can flip an Ellipse object horizontally using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will have to create an instance of fabric.Ellipse class and add it to the canvas. We can flip an ellipse object horizontally using the flipX property. Syntax new fabric.Ellipse({ flipX: Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ... Read More
In this tutorial, we are going to learn how to disable the centered scaling of Textbox using FabricJS. We can customize, stretch or move around the text written in a textbox. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. When being scaled via controls, assigning a true value to the centeredScaling property, uses the center as the object's origin of transformation. Syntax new fabric.Textbox(text: String, { centeredScaling: Boolean }: Object) Parameters ... Read More
In JavaScript, converting strings to arrays is a common task when you need to split text into characters or words for processing. JavaScript provides several built-in methods to accomplish this conversion efficiently. This article explores four different methods to convert strings to arrays, each suitable for different use cases and requirements. Using the split() Method The split() method is the most versatile approach for string-to-array conversion. It splits a string into an array of substrings based on a specified separator and returns a new array without modifying the original string. The split() method accepts two optional ... Read More
Suppose we have an array of arrays that contains the marks of some students in some subjects like this − const arr = [ ["English", 52], ["Hindi", 154], ["Hindi", 241], ["Spanish", 10], ["French", 65], ["German", 98], ["Russian", 10] ]; We are required to write a JavaScript function that takes in one such array and returns an object of objects. The return object should contain an object for each unique subject, and that object should contain information like the number of appearances ... Read More
We are required to write a JavaScript function that takes in an array of numbers that might contain some repeating numbers. The function should sort the array such that the elements that are repeated for the least number of times appears first followed by the elements with increasing frequency. For example − If the input array is − const arr = [1, 1, 2, 2, 2, 3]; Then the sorted array should be − const output = [3, 1, 1, 2, 2, 2]; How It Works The solution ... Read More
Armstrong Numbers: A positive integer is called an Armstrong number (of order n) if − abcd... = a^n + b^n + c^n + d^n + ... where n is the number of digits. For example, 153 is an Armstrong number because 1³ + 5³ + 3³ = 1 + 125 + 27 = 153. We are required to write a JavaScript function that takes in an array of exactly two numbers specifying a range. The function should return an array of all the Armstrong numbers that falls in that range (including the start and end ... Read More
Problem We need to write a JavaScript function that takes an array of coordinates and a number as arguments. The function should find and return the specified number of closest points to the origin (0, 0) using Euclidean distance. The Euclidean distance between a point (x, y) and the origin is calculated as: √(x² + y²) Example Input and Output For the input: const arr = [[3, 3], [5, -1], [-2, 4]]; const num = 2; The expected output should be: [[3, 3], [-2, 4]] Solution Using Sort ... Read More
JavaScript provides several efficient methods to remove all spaces from a string. This is a common requirement in web development for tasks like data validation, formatting user input, or preparing strings for processing. Problem Statement Given a string containing spaces, we need to remove all space characters to create a continuous string without any gaps. Sample Input: "Hello world! This is a test string." Sample Output: "Helloworld!Thisisateststring." Methods to Remove Spaces We'll explore four different approaches to solve this problem: Using Regular Expression with ... Read More
When dividing 1 by certain numbers, the decimal result may have a repeating pattern. This function finds the length of that repeating decimal part, but only for numbers that are coprime with 10 (share no common factors except 1). Problem Statement We need to write a JavaScript function that: Checks if a number is coprime with 10 (shares no common factors except 1) If not coprime, returns -1 If coprime, returns the length of the repeating decimal part when 1 is divided by that number ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance