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
Greatest number in a dynamically typed array in JavaScript
We are required to write a JavaScript function that takes in an array that contains some numbers, some strings and some false values. Our function should return the biggest Number from the array. For example: If the input array is − const arr = [23, 'hello', undefined, null, 21, 65, NaN, 1, undefined, 'hii']; Then the output should be 65. Using Math.max with Array Filtering The most straightforward approach is to filter valid numbers first, then use Math.max(): const arr = [23, 'hello', undefined, null, 21, 65, NaN, 1, undefined, 'hii']; ...
Read MoreJavaScript Bubble sort for objects in an array
Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list and swapping adjacent elements if they are in the wrong order. When applied to an array of objects, we can sort based on specific properties. The Shoe Class Let's start with a constructor class that creates Shoe objects: class Shoe { constructor(name, price, type) { this.name = name; this.price = price; this.type = ...
Read MoreHow to write the factorial function with reduce and range in JavaScript?
In this tutorial, we'll learn how to calculate factorials using JavaScript's reduce() method combined with array generation techniques. This approach demonstrates functional programming concepts while solving a common mathematical problem. Understanding reduce() and range Functions The reduce() function processes an array and reduces it to a single value by applying a function to each element. It takes an accumulator (which stores the result) and the current array value as parameters. const nums = [1, 2, 3, 4, 5]; const sum = nums.reduce((acc, val) => acc + val, 0); console.log(sum); 15 For ...
Read MoreCommon Character Count in Strings in JavaScript
In JavaScript, finding common characters between two strings involves counting how many characters appear in both strings. This is useful for text analysis, similarity comparisons, and string manipulation tasks. Understanding the Problem The goal is to count common characters between two strings, considering frequency. For example, if we have "abaac" and "baaaa", the common characters are 'a' (appears 3 times in first string, 4 times in second, so we count 3) and 'b' (appears 1 time in both, so we count 1), giving us a total of 4 common characters. Algorithm Step 1: Create a function ...
Read MoreNumber of digits that divide the complete number in JavaScript
We are required to write a JavaScript function that takes in a number as the first and the only argument. The function should count and return the number of digits present in the number that completely divide the number. For example, if the input number is 148, the output should be 2 because 148 is exactly divisible by 1 and 4 but not 8. Example Input and Output Input: 148 Output: 2 This is because: 148 ÷ 1 = 148 (divisible) 148 ÷ 4 = 37 (divisible) ...
Read MoreTurn each character into its ASCII character code and join them together to create a number in JavaScript
Problem We need to write a JavaScript function that takes a string and converts each character to its ASCII code, joins them to create a number, replaces all instances of 7 with 1, and returns the difference between the original and modified numbers. Understanding the Process The algorithm involves several steps: Convert each character to its ASCII code using charCodeAt() Join all ASCII codes to form one large number Replace all occurrences of digit 7 with 1 Calculate the difference between original and modified numbers ...
Read MorePlacing integers at correct index in JavaScript
We need to write a JavaScript function that takes a string containing only square brackets '[' and ']' and determines the minimum number of brackets to add to make it balanced. Problem Statement Given a string consisting of only '[' and ']' characters, find the minimum number of brackets that need to be added to make the string valid (properly balanced). A valid bracket string means every opening bracket '[' has a corresponding closing bracket ']' that comes after it. Example Input and Output Input: const str = '[]]'; Output: 1 ...
Read MoreHow to create a canvas with a wait cursor using FabricJS?
In this article, we are going to create a canvas with a wait cursor using FabricJS. A wait cursor can be used to indicate a busy program in the background which also stops the user from interacting with the interface. wait is one of the native cursor style available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc. that reuse the native cursor under the hood. Each of these cursors look slightly different based on operating system. Syntax new fabric.Canvas(element: HTMLElement|String, { defaultCursor: ...
Read MoreHow to flip a Circle vertically using FabricJS?
In this tutorial, we are going to learn how we can flip a Circle object vertically using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will have to create an instance of fabric.Circle class and add it to the canvas. We can flip a circle object vertically using the flipY property. Syntax new fabric.Circle({ flipY: Boolean }: Object) Parameters ...
Read MoreHow to create a Triangle with border colour using FabricJS?
In this tutorial, we are going to create a Triangle with border colour 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. Since FabricJS is extremely flexible, we are allowed to customize our Triangle object in any way we like. One of the properties that FabricJS provides is borderColor which allows us to manipulate the colour of the border when our object is active. Syntax new fabric.Triangle({ borderColor: String }: Object) ...
Read More