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
Computing Ackerman number for inputs in JavaScript
The Ackermann Function is a classic example of a recursive function that grows extremely quickly. It's notable for being a total computable function that is not primitive recursive, making it an important concept in theoretical computer science. Problem Statement We need to write a JavaScript function that takes two non-negative integers, m and n, and returns the Ackermann number A(m, n) defined by the following mathematical definition: A(m, n) = n+1 if m=0 A(m, n) = A(m-1, 1) if m>0 and n=0 A(m, n) = A(m-1, A(m, n-1)) if m>0 and n>0 Implementation ...
Read MoreHow to lock the flipping during scaling of Ellipse using FabricJS?
In this tutorial, we are going to learn how to lock the flipping during 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 flipping an object during scaling. This can be done by using the lockScalingFlip property. Syntax new fabric.Ellipse({ lockScalingFlip : Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. Using this parameter color, cursor, ...
Read MoreFind specific key value in array of objects using JavaScript
When working with JavaScript objects containing arrays of nested objects, you often need to find which parent key contains an object with specific property values. This is common when dealing with product catalogs, user groups, or categorized data. Example Data Structure Consider this product catalog object where each category contains an array of products: const obj = { "LAPTOP": [{ "productId": "123" }], "DESKTOP": [{ "productId": "456" ...
Read MoreAll possible odd length subarrays JavaScript
In this problem statement, our task is to find all the possible odd length subarrays with the help of JavaScript functionalities. This task can be done with the help of some built-in functions of JavaScript or we can solve it by multiple for loops. Logic for the Given Problem The problem states that we have to get all the possible odd length subarrays in JavaScript programming language. The meaning of odd length is that the length of the subarrays should be 1, 3, 5, 7, and so on. So our task is to filter the subarrays with odd ...
Read MoreLarge to Small Sorting Algorithm of already sorted array in JavaScript
Suppose we have an array of integers that is already sorted in the increasing order. We are required to write a JavaScript function that without using the inbuilt Array.prototype.sort() method sorts the array like the following − First number should be the maximum Second number should be the minimum Third number should be the 2nd ...
Read MoreValidating push pop sequence in JavaScript
Validating push/pop sequences is a common stack problem where we need to verify if a given pop sequence could result from a specific push sequence on an initially empty stack. Problem Statement Given two arrays pushed and popped containing unique elements, determine if the pop sequence could be achieved from the push sequence using stack operations. const pushed = [1, 2, 3, 4, 5]; const popped = [4, 5, 3, 2, 1]; How It Works The algorithm simulates stack operations by maintaining a stack and two pointers. We push elements until the stack ...
Read MoreValidating a boggle word using JavaScript
A Boggle board is a 2D array of individual characters. We need to validate whether a given word can be formed by connecting adjacent cells (horizontally, vertically, or diagonally) without reusing any previously used cells. Problem Given a Boggle board like this: const board = [ ["I", "L", "A", "W"], ["B", "N", "G", "E"], ["I", "U", "A", "O"], ["A", "S", "R", "L"] ]; We need to check if words like "BINGO" or "LINGO" are valid. Valid words are ...
Read MoreAdding binary without converting in JavaScript
Adding binary numbers without converting to decimal requires simulating manual binary addition with carry handling. This approach processes bits from right to left, just like traditional addition. Problem Statement We need to write a JavaScript function that takes two binary strings and returns their sum as a binary string, without converting to decimal numbers. Input: const str1 = '1101'; const str2 = '10111'; Expected Output: '100100' Algorithm Overview The solution works by: Reversing both strings to process from least significant bit Adding corresponding bits with carry propagation Building the ...
Read MoreHow to lock the horizontal movement of Ellipse using FabricJS?
In this tutorial, we are going to learn how to lock the horizontal 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 Y-axis. This can be done by using the lockMovementX property. Syntax new fabric.Ellipse({ lockMovementX: Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. ...
Read MoreCode to construct an object from a string in JavaScript
We are required to write a function that takes in a string as the first and the only argument and constructs an object with its keys based on the unique characters of the string and value of each key being defaulted to 0. For example: If the input string is − const str = 'hello world!'; Output Then the output object should be − const obj = { "h": 0, "e": 0, "l": 0, "o": 0, " ": 0, "w": 0, "r": 0, "d": 0, "!": 0 }; Using Array.reduce() ...
Read More