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
Can the string be segmented in JavaScript
The string segmentation problem determines if a given string can be broken down into words that exist in a provided dictionary. This is a classic dynamic programming problem with practical applications in natural language processing and text analysis. What is String Segmentation? String segmentation involves breaking a continuous string into meaningful words using a dictionary. For example, given the string "haveapplepie" and dictionary ["have", "apple", "pie"], we can segment it as "have" + "apple" + "pie". // Example visualization const dictionary = ["apple", "have", "pie"]; const input = "haveapplepie"; // Can be segmented as: "have" + ...
Read MoreAlternative sorting of an array in JavaScript
We need to write a JavaScript function that sorts an array in an alternating pattern where elements follow the sequence: smaller, larger, smaller, larger, and so on. The pattern we want to achieve is: arr[0] < arr[1] > arr[2] < arr[3] > arr[4] < arr[5]... This creates a zigzag or wave-like pattern in the sorted array. There can be multiple valid solutions for any given input array. Example Input and Output For an input array: const arr = [1, 2, 3, 4, 5, 6]; One possible output could be: ...
Read MoreFinding the longest non-negative sum sequence using JavaScript
Problem We are required to write a JavaScript function that takes in an array containing a sequence of integers, each element of which contains a possible value ranging between -1 and 1. Our function should return the size of the longest sub-section of that sequence with a sum of zero or higher. Understanding the Algorithm The solution uses a prefix sum approach with an index mapping technique. It tracks cumulative sums and uses an array to store the first occurrence of each sum value, allowing efficient calculation of subarray lengths. Example Following is the ...
Read MoreHow to create a Circle with border colour using FabricJS?
In this tutorial, we are going to create a Circle with border colour using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will create an instance of fabric.Circle class and add it to the canvas. Since FabricJS is extremely flexible, we are allowed to customize our circle 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.Circle({ borderColor: String }: Object) Parameters ...
Read MoreHow to find the sum of all elements of a given array in JavaScript?
In JavaScript, finding the sum of all elements in an array is a common operation. This tutorial covers different methods to achieve this, from traditional loops to modern array methods. Using the for Loop The for loop is the most straightforward approach to sum array elements. It provides full control over the iteration process and is easy to understand. Example Sum Array Elements Finding sum using for loop: ...
Read MoreHow to crop the width in a cloned image using FabricJS?
In this tutorial, we are going to learn how to crop the width in a cloned image using FabricJS. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to crop the width in a cloned image, we use the width property with the cloneAsImage method. Syntax cloneAsImage(callback: function, options: Object): fabric.Object Parameters callback (optional) − This parameter is a function which is ...
Read MoreGenerate PDF in ElectronJS
Electron is a popular framework for building cross-platform desktop applications using JavaScript, HTML, and CSS. One common requirement in desktop applications is the ability to generate PDF documents programmatically. In this article, we will explore how to generate PDF files in Electron using the jsPDF library. We will cover the basics of PDF generation, installation steps, and various customization options to create professional-looking documents. PDF (Portable Document Format) is a file format developed by Adobe Systems that preserves document formatting across different platforms and devices. PDF files can contain text, images, tables, and other elements while maintaining consistent ...
Read MoreDifferences in two strings in JavaScript
We are required to write a JavaScript function that takes in two strings and find the number of corresponding dissimilarities in the strings. The corresponding elements will be dissimilar if they are not equal at the same position. Example Strings Let's say the following are our strings: const str1 = 'Hello world!!!'; const str2 = 'Hellp world111'; In this case, we need to compare each character at the same index and count how many positions have different characters. Method 1: Using a For Loop const str1 = 'Hello world!!!'; const str2 ...
Read MoreRemoving property from a JSON object in JavaScript
A JSON (JavaScript Object Notation) object is a data structure surrounded by curly braces {}. JSON objects contain key-value pairs where keys must be strings and values can be numbers, strings, objects, booleans, arrays, or null. JavaScript provides several methods to remove properties from objects. Each method has different characteristics - some modify the original object, while others create new objects without the unwanted properties. Basic JSON Object Structure Here's the basic syntax for a JSON object: const jsonObject = { "name": "John", "age": 30, "city": ...
Read MoreCase-sensitive sort in JavaScript
JavaScript's default sort() method performs case-sensitive sorting but places uppercase letters before lowercase letters. This article demonstrates how to implement true case-sensitive sorting where special characters and numbers come first, followed by lowercase letters, then uppercase letters. JavaScript Case Sensitivity JavaScript is case-sensitive, meaning it treats uppercase and lowercase letters as completely different characters. const language = "JavaScript"; const Language = "React"; const x = 100; console.log(language); console.log(Language); console.log(x); JavaScript React 100 Default Sort Behavior JavaScript's sort() method converts elements to strings and sorts by UTF-16 character codes. By ...
Read More