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
Counting adjacent pairs of words in JavaScript
We are required to write a JavaScript function that takes in a string str that represents a sentence as the only argument. Our function should count and return the adjacent pair of identical words present in the string str. Our function should check the words ignoring their case, which means 'it' and 'It' should be counted as identical. Problem Statement For example, if the input to the function is: const str = 'This this is a a sample string'; The expected output should be: 2 Output Explanation: Because the ...
Read MoreHow to lock the horizontal skewing of Ellipse using FabricJS?
In this tutorial, we are going to learn how to lock the horizontal skewing 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 skewing an object horizontally. This can be done by using the lockSkewingX property. Syntax new fabric.Ellipse({ lockSkewingX : Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. ...
Read MoreRepeated sum of Number's digits in JavaScript
We are required to write a JavaScript function that recursively sums up the digits of a number until it reduces to a single digit number. We are required to do so without converting the number to String or any other data type. How It Works The algorithm uses two functions: sumDigit(): Recursively extracts and sums all digits of a number sumRepeatedly(): Repeatedly calls sumDigit() until result is a single digit Example Let's implement the solution step by step: const num = 546767643; const sumDigit = (num, sum = 0) => ...
Read MoreCalculating Josephus Permutations efficiently in JavaScript
This problem takes its name from arguably the most important event in the life of the ancient historian Josephus. According to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege. Refusing to surrender to the enemy, they instead opted for mass suicide, with a twist — they formed a circle and proceeded to kill one man every three, until one last man was left (and that it was supposed to kill himself to end the act). Josephus and another man were the last two and, as we now know ...
Read MoreDynamic Programming - Part sum of elements JavaScript
In this problem, we calculate the sum of all elements except one element at each step, creating an array of partial sums. We'll implement this using JavaScript array methods and dynamic programming concepts. Problem Statement Given an array of n elements, generate an array containing: The sum of all elements The sum of all elements except the first element The sum of all elements except the second element And so on for each element Algorithm Step 1: Calculate the total sum of all elements in the array. Step 2: Create a result array starting ...
Read MoreSplitting number into n parts close to each other in JavaScript
We are required to write a JavaScript function that takes in a number, num, as the first argument and another number, parts, as the second argument. Our function should split the number num into exactly parts numbers while keeping these conditions in mind: The numbers should be as close as possible The numbers should be even (if possible) The ordering of numbers is not important. Problem Analysis To split a number into n parts as evenly as possible, we need to: Calculate ...
Read MoreHow to lock the rotation of Ellipse using FabricJS?
In this tutorial, we are going to learn how to lock the rotation 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 rotate or not. This can be done by using the lockRotation property. Syntax new fabric.Ellipse({ lockRotation : Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. Using this ...
Read MoreHow to create an array of partial objects from another array in JavaScript?
Arrays are one of the most commonly used data types in JavaScript. They are used to store collections of data and allow for efficient access and manipulation of data. Arrays can contain any type of data, including primitive values, objects, and even other arrays. The technique of creating an array of partial objects from an array is a valuable technique when dealing with complex data sets. Partial objects contain only a subset of the data from the original array, allowing us to focus on a particular set of data. This can be especially useful when dealing with large data ...
Read MoreReorder an array in JavaScript
Reordering an array means changing the sequence of elements within the array. JavaScript provides several built-in methods to reorder arrays, each serving different purposes. Using sort() for Alphabetical Ordering The sort() method sorts array elements alphabetically in ascending order by default. It modifies the original array. const states = ["Telangana", "Uttar Pradesh", "Karnataka", "Kerala", "TamilNadu"]; document.getElementById("para1").innerHTML = "Original: " + states; states.sort(); ...
Read MoreHow to split comma and semicolon separated string into a two-dimensional array in JavaScript ?
Let's say we have a variable "users" that contains the following string of text where each user is separated by a semicolon and each attribute of each users is separated by a comma − const users = 'Bob, 1234, Bob@example.com;Mark, 5678, Mark@example.com'; We are required to write a JavaScript function that takes in one such string and splits this into a multidimensional array that looks like this − const arr = [ ['Bob', 1234, 'Bob@example.com'], ['Mark', 5678, 'Mark@example.com'] ]; Method 1: Using split() and for Loop ...
Read More