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
How to merge two strings alternatively in JavaScript
In JavaScript, merging two strings alternatively means combining characters from both strings one by one. This creates a new string where characters alternate between the first and second input strings. For example, if we have two strings: const str1 = 'abc'; const str2 = 'def'; console.log('String 1:', str1); console.log('String 2:', str2); String 1: abc String 2: def The expected output should be: adbecf Using Loop-Based Approach Here's a function that merges two strings alternatively by iterating through both strings simultaneously: const str1 = 'abc'; const ...
Read MoreGet price value from span tag and append it inside a div after multiplying with a number in JavaScript?
In JavaScript, you can extract a numeric value from a span element, multiply it, and display the result in another element. This involves getting the text content, converting it to a number, performing the calculation, and updating the DOM. HTML Structure First, let's create a proper HTML structure with a span containing the price and a div to display the result: Price Calculator Original ...
Read MoreJavaScript checking if all the elements are same in an array
In this article, we will learn to check if all the elements are the same in an array in JavaScript. Finding all elements of an array to be the same is a frequent problem in JavaScript, usually needed for data validation, game logic, and algorithm building. Problem Statement We are required to write a JavaScript function that takes in an array of literals. The function should find whether or not all the values in the array are the same. If they are the same, the function should return true, or false otherwise. For Example Input ...
Read MoreReturn the element that appears for second most number of times in the array JavaScript
In JavaScript, finding the element that appears for the second most number of times in an array requires counting frequencies and identifying the second highest count. We'll use a frequency map and sorting to solve this problem efficiently. Understanding the Problem Given an array of elements, we need to find the element with the second highest frequency. For example, in the array [1, 3, 3, 4, 4, 4], the element 4 appears 3 times (most frequent), and 3 appears 2 times (second most frequent), so we return 3. Algorithm Steps Step 1: Create a frequency map ...
Read MoreFind the greatest product of three numbers in JavaScript
In JavaScript, finding the greatest product of three numbers from an array requires considering both positive and negative numbers. This problem has multiple approaches, from brute force to optimized sorting methods. Understanding the Problem Given an array of integers, we need to find three numbers whose product is the largest among all possible combinations. For example, with array [1, 5, 3, 2, 4], the three largest numbers (3, 4, 5) give us the product 3 × 4 × 5 = 60. ...
Read MoreLargest product of n contiguous digits of a number in JavaScript
We are required to write a JavaScript function that takes in two numbers as first and the second argument, let us call them m and n. The first number will generally be a number with multiple digits and the second number will always be smaller than the number of digits in the first number. The function should find the group of n consecutive digits from m whose product is the greatest. For example, if the input numbers are: const m = 65467586; const n = 3; Then the output should be: ...
Read MoreNth smallest element in sorted 2-D array in JavaScript
In JavaScript, finding the Nth smallest element in a sorted 2D array requires an efficient approach. We'll use binary search on the value range rather than indices. Problem Statement Given a sorted 2D array (sorted in increasing order both row-wise and column-wise), find the Nth smallest element. const arr = [ [ 1, 5, 9], [10, 11, 13], [12, 13, 15] ]; For example, if we want the 5th smallest element from the above array, the answer would be 11. Approach: Binary Search on Values ...
Read MoreSum all perfect cube values upto n using JavaScript
Problem We are required to write a JavaScript function that takes in a number n and returns the sum of all perfect cube numbers smaller than or equal to n. Understanding Perfect Cubes Perfect cubes are numbers that can be expressed as n³ where n is an integer. For example: 1³ = 1, 2³ = 8, 3³ = 27, 4³ = 64, etc. Example Following is the code − const num = 23546; const sumPerfectCubes = (num = 1) => { let i = 1; let sum = 0; while(i * i * i
Read MoreHow to set the position of an Ellipse from left using FabricJS?
In this tutorial, we are going to learn how to set the position of an Ellipse from the left using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will create an instance of fabric.Ellipse class and add it to the canvas. We can manipulate an ellipse object by changing its position, opacity, stroke and also its dimension. The position from left can be changed by using the left property. Syntax new fabric.Ellipse( { left: Number }: Object) Parameters ...
Read MoreHow to disable the centered rotation of Triangle using FabricJS?
In this tutorial, we are going to learn how to disable the centered rotation of Triangle using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we will have to create an instance of fabric.Triangle class and add it to the canvas. By default, all objects in FabricJS use their center as the point of rotation. However, we can change this behaviour by using the centeredRotation property. Syntax new fabric.Triangle({ centeredRotation: Boolean }: Object) Parameters ...
Read More