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
Modify an array based on another array JavaScript
When working with arrays in JavaScript, you might need to modify one array based on patterns or elements found in another array. This article demonstrates how to join consecutive elements from a reference array when they appear as combined phrases in a second array. Problem Statement Suppose we have a reference array of individual words: const reference = ["your", "majesty", "they", "are", "ready"]; And we want to modify it based on another array that contains some words joined together: const another = ["your", "they are"]; The goal is to create ...
Read MoreFinding the length of second last word in a sentence in JavaScript
A sentence is just a string which contains strings (called words) joined by whitespaces. We are required to write a JavaScript function that takes in one such sentence string and count the number of characters in the second to last word of the string. If the string contains no more than 2 words, our function should return 0. For example − If the input string is − const str = 'this is an example string'; Then the output should be − const output = 7; because the number of characters ...
Read MoreFinding life path number based on a date of birth in JavaScript
A person's Life Path Number is calculated by adding each individual digit in that person's date of birth, then reducing it to a single digit number through repeated digit summation. Problem We need to write a JavaScript function that takes a date in "yyyy-mm-dd" format and returns the life path number for that date of birth. How It Works The calculation involves three steps: Sum all digits in the year, month, and day separately Reduce each sum to a single digit by adding digits repeatedly Add the three single digits and reduce to final ...
Read MoreConverting array to phone number string in JavaScript
To convert an array to a phone number string in JavaScript can be done by formatting the array elements into the desired phone number pattern. Following are the steps to learn how to convert array to phone number string in Javascript − Ensure that the array has the correct number of elements (usually 10 for a standard phone number). Join the elements of the array into a single string. Format the string into the desired phone number pattern, such as (XXX) XXX-XXXX. Let ...
Read MoreHow to create an Ellipse with help cursor on hover over objects using FabricJS?
In this tutorial, we are going to create an Ellipse with a help cursor on hover over objects using FabricJS. help is one of the native cursor styles 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 which are reusing the native cursor underhood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Ellipse({ hoverCursor: String }: Object) Parameters options (optional) ...
Read MoreHow to create a Textbox with border colour using FabricJS?
In this article, we are going to create a Textbox with border colour using FabricJS. We can customize, stretch or move around the text written in a textbox. We can also customize the text itself by using properties like fontSize, fontFamily, fontStyle, fontWeight etc. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. 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.Textbox(text: String, { borderColor: String ...
Read MoreHow to find the binomial coefficient of two integers using JavaScript?
In this tutorial, we are going to learn how to find the binomial coefficient of two integers using JavaScript. Before learning it we should know what binomial coefficient is and what it refers to. What are Binomial Coefficients? Binomial coefficients refer to the positive integers that occur as coefficients in the binomial theorem. A binomial coefficient C(n, k) can be defined as the coefficient of x^k in the expansion of (1 + x)^n. A binomial coefficient of two numbers n and k signifies the number of combinations of k items that can be selected from a ...
Read MoreGroup Similar Items in JSON in JavaScript
Suppose, we have a JSON Array that contains data about some tickets like this: const arr = [ { "quantity": "1", "description": "VIP Ticket to Event" }, { "quantity": "1", "description": "VIP Ticket to Event" }, { "quantity": ...
Read MoreNumber of letters in the counting JavaScript
We are required to write a JavaScript function that takes in a number, say n. The function should count the letters in the number names from 1 to n. For example − If n = 5; Then the numbers are one, two, three, four, five. And the total number of letters are 19, so the output should be 19. How It Works The algorithm uses arrays to store the letter count for each digit position and handles special cases like teens (11-19) and compound numbers (hundred, thousand). Example const sumUpto = (num = ...
Read MoreFinding desired numbers in a sorted array in JavaScript
We have an array of integers which is sorted in the increasing order. We are required to write a JavaScript function that takes in one such array as the first argument and a target sum number as the second argument. The function should find and return two such numbers from the array that when added gives the target sum. The condition for solving this problem is that we have to do this in linear time and using constant space. Two Pointer Approach The optimal solution uses the two-pointer technique. Since the array is sorted, we can place ...
Read More