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
JavaScript - summing numbers from strings nested in array
When working with arrays containing string numbers (like credit card numbers), you often need to extract and sum the numeric values. This article shows how to find the string with the greatest sum of digits. Problem Statement Given an array of credit card numbers as strings, we need to find the card with the highest sum of digits. If multiple cards have the same sum, return the last one encountered. const arr = ['4916-2600-1804-0530', '4779-252888-3972', '4252-278893-7978', '4556-4242-9283-2260']; Solution Approach The solution involves two main steps: extracting numbers from each string and calculating their ...
Read MoreArray thirds with equal sums in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the first and the only argument. Our function should return true if and only if we can partition the array into three non-empty parts with equal sums, false otherwise. Problem Statement Given an array of integers, determine if it can be split into exactly three contiguous subarrays with equal sums. For example, if the input to the function is: const arr = [3, 3, 6, 5, -2, 2, 5, 1, -9, 4]; Then the output should be: ...
Read MoreDecrypting source message from a code based on some algorithm in JavaScript
We need to write a JavaScript function that decrypts a message by reversing an encryption algorithm. The encryption process involves reversing the string and replacing letters with their ASCII codes in quotes. Understanding the Encryption Algorithm The original encryption algorithm works as follows: Reverse the message string Replace every letter with its ASCII code in quotes (A becomes '65', h becomes '104') Keep digits and spaces unchanged The Decryption Function To decrypt, we need to reverse this process by applying the same algorithm to the encrypted message: const str = '12 hello ...
Read MoreFinding the final direction of movement in JavaScript
Problem We need to write a JavaScript function that takes an array of directional characters and finds the final direction after canceling out opposite movements. The array contains only 4 possible characters: 'N' → stands for North direction 'S' → stands for South direction 'W' → stands for West direction 'E' → stands for East direction Each character represents a unit move in that direction. When opposite directions ('S' and 'N') or ('E' and 'W') appear adjacently, they cancel each other out. Our ...
Read MoreHow to add stroke to an Ellipse using FabricJS?
In this tutorial, we are going to learn how to add stroke to an Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we have to create an instance of fabric.Ellipse class and add it to the canvas. Our ellipse object can be customized in various ways like changing its dimensions, adding a background color or by changing the color of the line drawn around the object. We can do this by using the stroke property. Syntax new fabric.Ellipse({ stroke: String }: Object) Parameters ...
Read MoreHow to add stroke to a Textbox using FabricJS?
In this tutorial, we are going to learn how to add stroke to a 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. Our textbox object can be customized in various ways like changing its dimensions, adding a background colour, or by changing the colour of the line drawn around the object. We can do this by using the stroke property. Syntax new fabric.Textbox(text: String, { stroke : ...
Read MoreHow to use map() on an array in reverse order with JavaScript?
The map() method creates a new array by transforming each element. Sometimes you need to process array elements in reverse order. Here are three effective approaches to achieve this. Introduction to map() Method Syntax array.map((element, index, array) => { return element + 20; }) Parameters element – The current array element being processed index – The index of the current element array – The original array being mapped Method 1: Reverse Array Then Map First reverse the array using reverse(), then apply map() to the reversed ...
Read MoreAll combinations of sums for array in JavaScript
We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a number, say n as the second argument. The number n will always be less than or equal to the length of the array. Our function should return an array of the sum of all elements of all the possible subarrays of length n from the original array. For example, If the input is: const arr = [2, 6, 4]; const n = 2; Then the output should be: const output = ...
Read MoreJavaScript - Find keys for the matched values as like query in SQL
In JavaScript, you can filter object properties based on value matching, similar to SQL's WHERE clause with LIKE operator. This is useful for searching through data structures and finding keys that match specific criteria. Problem Statement Given an object with key-value pairs, we need to find all keys whose values contain a specific search term (case-insensitive). const obj = { "100": "Jaipur", "101": "Delhi", "102": "Raipur", "104": "Goa" }; We want to create a function that returns ...
Read MoreJavaScript Quicksort Recursive
In this article, we will learn to implement Quicksort recursively in JavaScript. Quicksort is one of the most efficient and widely used sorting algorithms, known for its divide-and-conquer approach. What is Quicksort? Quicksort is a divide-and-conquer sorting algorithm that sorts an array by selecting a pivot element and partitioning the array into two subarrays: elements smaller than the pivot and elements greater than or equal to the pivot. It then recursively sorts the subarrays. Quicksort Process ...
Read More