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
Count and return the number of characters of str1 that makes appearances in str2 using JavaScript
We need to write a JavaScript function that takes two strings as parameters and counts how many characters from the first string appear in the second string, including duplicate occurrences. Problem Statement Given two strings str1 and str2, count how many characters from str1 also appear in str2. If a character appears multiple times in str2, count each occurrence separately. Example: str1 = 'Kk' contains characters 'K' and 'k' str2 = 'klKKkKsl' contains: k(1), l(1), K(2), K(3), k(4), K(5), s(6), l(7) Characters from str1 found in str2: k, K, K, k, K = 5 matches ...
Read MoreHow to set the angle of skew on the Y-axis of a Triangle using FabricJS?
In this tutorial, we are going to learn how to set the angle of skew on the y-axis of a 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. Our triangle object can be customized in various ways like changing its dimensions, adding a background color or by changing the angle of skew on the Y-axis. We can do this by using the skewY property. Syntax new fabric.Triangle({ skewY : ...
Read MoreFabricJS – How to set the stroke colour of the controlling corners of a Line?
In this tutorial, we are going to learn about how to set the stroke colour of controlling corners of Line using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. The cornerStrokeColor property allows us to ...
Read MoreHow to create a hash from a string in JavaScript?
Before we start, let's understand the hash in JavaScript. The hash is also a string, but it's encrypted using a particular algorithm. Generally, we use the hash for security purposes. For example, Google stores users' emails and passwords in their database. Now, Google's employees can access their database for development purposes. But can they get the user's email and password from the database? No, because the password is stored in the hash form, and to decrypt the password, the employee needs the key which we used while creating the hash from the password string. So, in such a ...
Read MoreReturn a map representing the frequency of each data type in an array in JavaScript
We are required to write a JavaScript function that takes in an array that contains elements of different data types and the function should return a map representing the frequency of each data type. Let's say the following is our array − const arr = [23, 'df', undefined, null, 12, { name: 'Rajesh' }, [2, 4, 7], 'dfd', null, Symbol('*'), 8]; Understanding the Problem We need to count how many times each JavaScript data type appears in the array. JavaScript's typeof operator will help us identify the data type of each ...
Read MoreHow to get single array from multiple arrays in JavaScript
In this article, we will explore how to combine multiple arrays into a single array in JavaScript. This is a common task when working with data manipulation and array operations. We will cover three effective methods: the spread operator (ES6), the concat() method, and using push() with the spread operator. Each approach has its own advantages and use cases. Understanding the Problem When working with multiple arrays, you often need to merge them into one continuous array while maintaining the original order of elements. Input Arrays: ...
Read MoreAlgorithm to add binary arrays in JavaScript
In this problem statement, our target is to add two binary arrays with the help of JavaScript. So we will break down the problem step by step to ensure understanding. What is a Binary Array? A binary array is an array that represents a binary number. In a binary number system we have only two possible digits, 0 and 1. The binary array will have elements which can only be 0s and 1s. Every item in the array represents a bit of the binary number. For example, we have a binary array [1, 0, 1, 0]. This ...
Read MoreConverting to hex and summing the numeral part in JavaScript
We are required to write a JavaScript function that takes in a string, converts every character to its hex ASCII value, then sums only the numeric digits (0-9) from the hex representation, ignoring letters (a-f). Problem Given a string, we need to: Convert each character to its ASCII code Convert ASCII codes to hexadecimal Extract only numeric digits from the hex strings Sum all the numeric digits Example Let's see how this works with a complete example: const str = "Hello, World!"; const toHexAndSum = (str = '') => { ...
Read MoreCreate palindrome by changing each character to neighboring character in JavaScript
We need to write a JavaScript function that determines if we can create a palindrome by changing each character to its neighboring character in the alphabet. Each character can only move one position forward or backward (except 'a' can only go to 'b' and 'z' can only go to 'y'). Problem Requirements The function must handle these constraints: Each character MUST be changed either to the one before or the one after in the alphabet "a" can only be changed to "b" and "z" to "y" Return true if at ...
Read MoreChecking for particular types of matrix in JavaScript
We need to write a JavaScript function that checks if every diagonal from top-left to bottom-right in a 2D matrix has identical elements. This is useful for pattern recognition and matrix analysis tasks. Problem Statement Given a 2D array, our function should verify that all elements in each diagonal (running from top-left to bottom-right) are the same. If this condition is met for all diagonals, return true, otherwise false. For example, consider this matrix: const arr = [ [6, 7, 8, 9], [2, 6, 7, 8], ...
Read More