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
Binary array to corresponding decimal in JavaScript
Problem We are required to write a JavaScript function that takes in a binary array (consisting of only 0 and 1). Our function should first join all the bits in the array and then return the decimal number corresponding to that binary. Method 1: Using Math.pow() with Manual Calculation This approach calculates the decimal value by iterating through the array and using powers of 2: const arr = [1, 0, 1, 1]; const binaryArrayToNumber = arr => { let num = 0; for (let i = ...
Read MoreFind and return the longest length of set in JavaScript
In JavaScript, finding the longest length of a set involves traversing array elements in a cycle pattern where each element points to the next index. This problem requires tracking visited elements to avoid infinite loops and find the maximum cycle length. Problem Statement Given an array of length N containing all integers from 0 to N-1, we need to find the longest set S where S[i] = {A[i], A[A[i]], A[A[A[i]]], ...}. We start from index i, then move to A[i], then to A[A[i]], and continue until we encounter a duplicate element. Example Input and Output For ...
Read MoreHow to Delete a Linked List in JavaScript?
In this article, we are going to explore Linked List and how to delete a linked list in JavaScript. A Linked List is a linear data structure where elements are not stored in contiguous memory locations. Each element (called a node) contains data and a pointer/reference to the next node in the sequence. ...
Read MoreWhat is the difference between undefined and not defined in JavaScript?
In JavaScript, understanding the difference between "undefined" and "not defined" is crucial for debugging and writing clean code. While they may seem similar, they represent fundamentally different states in JavaScript. What is Undefined? undefined is a primitive value in JavaScript that indicates a variable has been declared but not assigned a value. It's also the default return value for functions that don't explicitly return anything. Common Cases of Undefined Variables declared without initialization Object properties that don't exist Array elements that haven't been assigned ...
Read MoreTop must-know Features of JavaScript
In this tutorial, we will understand the special features of JavaScript that make it one of the most popular and versatile programming languages in the world. JavaScript is a dynamic programming language with flexible features and extensive library support. GitHub hosts millions of JavaScript projects, demonstrating its widespread adoption for both front-end and back-end development. Its simple syntax and browser compatibility make it accessible to developers with basic knowledge of HTML, CSS, and programming fundamentals. Core JavaScript Features Client-Side Scripting JavaScript executes directly in the browser, enabling interactive web pages without server round-trips. This allows for real-time ...
Read MoreHow to add the coordinates in a Polygon using FabricJS?
We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. We can add the coordinates in a polygon by using points property. Syntax new fabric.Polygon(points: Array, options: Object) Parameters points − This parameter accepts an Array which denotes the array of points that make up the polygon object. ...
Read MoreVariable defined with a reserved word const can be changed - JavaScript?
In JavaScript, variables declared with const cannot be reassigned, but this doesn't mean the contents of objects or arrays are immutable. You can still modify the properties of objects declared with const. Understanding const with Objects The const keyword prevents reassignment of the variable itself, but object properties can still be modified: const details = { firstName: 'David', subjectDetails: { subjectName: 'JavaScript' } }; // This works - modifying object properties details.firstName = 'John'; details.subjectDetails.subjectName = 'Python'; console.log(details); { firstName: 'John', subjectDetails: { ...
Read MoreChecking for the similarity of two 2-D arrays in JavaScript
We are required to write a JavaScript function that takes in two 2-D arrays and returns a boolean based on the check whether the arrays are equal or not. The equality of these arrays, in our case, is determined by the equality of corresponding elements. Both the arrays should have same number of rows and columns. Also, arr1[i][j] === arr2[i][j] should yield true for all i between [0, number of rows] and j between [0, number of columns] Method 1: Basic Nested Loop Approach This method compares each element position by position using nested loops: ...
Read MoreSubset with maximum sum in JavaScript
In JavaScript, finding the subset of non-adjacent elements with maximum sum is a classic dynamic programming problem. We need to decide whether to include each element or skip it, ensuring no two adjacent elements are selected. The key insight is that for each element, we have two choices: include it (and skip the previous element) or exclude it (and take the maximum sum up to the previous element). Problem Statement Given an array of integers, find the subset of non-adjacent elements that produces the maximum sum. Adjacent elements cannot be selected together. For example, with the ...
Read MoreGrouping words with their anagrams in JavaScript
Two words or phrases which can be made by arranging the letters of each other in a different order are called anagrams of each other, like "rat" and "tar". We need to write a JavaScript function that takes in an array of strings that might contain some anagram strings. The function should group all the anagrams into separate subarrays and return the new array thus formed. Problem Example If the input array is: const arr = ['rat', 'jar', 'tar', 'raj', 'ram', 'arm', 'mar', 'art']; Then the output array should be: const ...
Read More