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
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product JavaScript
Finding the pair of adjacent elements with the largest product is a common array problem in JavaScript. This involves iterating through the array and comparing products of consecutive elements. Problem Understanding Given an array of integers, we need to find two adjacent elements whose product is maximum among all possible adjacent pairs. For example, in array [1, 2, 3, 4], the adjacent pairs are (1, 2), (2, 3), and (3, 4) with products 2, 6, and 12 respectively. Method 1: Using -Infinity for Initialization This approach initializes the maximum product with -Infinity to handle arrays with ...
Read MoreTribonacci series in JavaScript
The tribonacci sequence is a generalization of the Fibonacci sequence where each term is the sum of the three preceding terms. Unlike Fibonacci which uses two preceding terms, tribonacci uses three. The standard tribonacci series starts with 0, 1, 1, and each subsequent term is the sum of the previous three terms: 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149... How It Works Each term after the first three follows the formula: T(n) = T(n-1) + T(n-2) + T(n-3) Where T(0) = 0, T(1) = 1, T(2) = 1 ...
Read MoreCrack Alphabets fight problem in JavaScript
Problem Consider a situation where armies of two teams of alphabets are fighting each other. Each soldier has a specific weight based on their letter: Team A (Positive Weights) Soldier Weight A ...
Read MoreHow to lock the vertical movement of Ellipse using FabricJS?
In this tutorial, we are going to learn how to lock the vertical movement of an Ellipse using FabricJS. Just as we can specify the position, color, opacity and dimension of an ellipse object in the canvas, we can also specify whether we want it to move only in the X-axis. This can be done by using the lockMovementY property. Syntax new fabric.Ellipse({ lockMovementY: Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. ...
Read MoreSquared concatenation of a Number in JavaScript
We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenated. For example: If the number is − 99 Then the output should be − 8181 because 9² is 81 and 9² is 81, so concatenating them gives 8181. Example Let's implement this function step by step: const num = 9119; const squared = num => { const numStr = String(num); ...
Read MoreFinding the least common multiple of a range of numbers in JavaScript?
We are required to write a JavaScript function that takes in an array of exactly two numbers specifying a range. The function should then calculate the least common multiple of all the numbers within that range and return the final result. Understanding LCM and GCD To find the LCM of multiple numbers, we first need helper functions for GCD (Greatest Common Divisor) and LCM of two numbers: GCD: The largest number that divides both numbers evenly LCM: The smallest positive number that is divisible by both numbers Formula: LCM(a, b) = (a × b) / ...
Read MoreChecking if a number is some power of the other JavaScript
In this problem statement, our objective is to check if a given input number is some power of another number using JavaScript functionalities. Logic for the Problem To determine if a number a is a power of another number b, we can use logarithms. If a = b^n for some integer n, then log_b(a) = n should be an integer. Since JavaScript's Math.log() returns the natural logarithm, we use the change of base formula: log_b(a) = ln(a) / ln(b). If this result is an integer, then a is a power of b. Algorithm Step 1 ...
Read MoreFinding n subarrays with equal sum in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the first argument and an integer as the second argument. The function should check whether we can create n (second argument) subarrays from the original array such that all the subarrays have the equal sum. For example − If the inputs are − const arr = [4, 3, 2, 3, 5, 2, 1]; const num = 4; The output should be true because the subarrays are: [5], [1, 4], [2, 3], [2, 3] all having sum equal ...
Read MoreArranging lexicographically and removing whitespaces in JavaScript
We need to write a JavaScript function that takes a string containing alphabets and whitespaces, then returns a new string with characters arranged in case-insensitive alphabetical order while removing whitespace and punctuation. Problem Statement Our function should iterate over the input string and concatenate characters into a new string following "case-insensitively-alphabetical-order-of-appearance" order. Whitespace and punctuation are simply removed. For example: Input: const str = 'some simple letter combination!'; Expected Output: abceeeeiiillmmmnnoooprssttt Solution Using Nested Loops The approach uses nested loops to iterate through each letter of the alphabet (a-z) ...
Read MoreHow to lock the vertical scaling of Ellipse using FabricJS?
In this tutorial, we are going to learn how to lock the vertical scaling of an Ellipse using FabricJS. Just as we can specify the position, color, opacity and dimension of an ellipse object in the canvas, we can also specify whether we want to stop scaling an object vertically. This can be done by using the lockScalingY property. Syntax new fabric.Ellipse({ lockScalingY : Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. ...
Read More