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
Javascript Articles
Page 34 of 534
How to Deep Merge Two Objects in JavaScript?
In JavaScript, a deep merge of two objects means creating a new object by combining properties recursively, including nested objects. Unlike a simple merge, it ensures that no nested properties are lost during the merge, which only replaces top-level properties. In this article, we will look at several ways of performing a deep merge of two objects, with code and explanations. Approaches to Deep Merge Manual Recursive Function Using Lodash's merge Method Using the Spread Operator with Recursion Using Object.assign with Recursion ...
Read MoreJavaScript Program for Searching an Element in a Linked List
To search for an element in a linked list, we need to go through each node one by one and check if its value matches the target element. If we find the element, we return its position in the list. If not, we return a message saying the element is not found. In this article, our task is to implement a JavaScript program that searches for a specific element in a linked list and returns its position if found, or a message if it is not present. Example Let's look at the below examples: Linked ...
Read MoreJavaScript Program for Left Rotation and Right Rotation of a String
To implement left rotation and right rotation of a string, we can use various approaches. Left rotation means moving characters counter-clockwise by a given number of positions, while right rotation means moving characters clockwise by a given number of positions. In this article we have a string and a value of k by which we will rotate the string. Our task is to write a JavaScript program for left rotation and right rotation of a string. Example Input: String str = "apple"; k = 3 Output: Left Rotation: "leapp" Right Rotation: "pleap" Approaches ...
Read MoreJavaScript program to find the average of all negative numbers in an array
In this problem, we are given an array of integers, which may contain both negative and positive numbers. We have to find the average of all the negative numbers in the array. In this article, we are going to learn how we can find the average of all negative numbers in an array using JavaScript. Problem Examples Example 1 Input: arr = [1, -3, 4, -2, -5]; Output: -3.33 Explanation: The negative numbers in the array are -3, -2, and -5. Their sum is -10, and the number of negative elements is 3. The average is: ...
Read MoreJavaScript Program to Find the average of all positive numbers in an array
In this article, we will learn how to find the average of all positive numbers in an array using JavaScript, along with examples to demonstrate the implementation. We are given an array of integers, which may contain both negative and positive numbers. Our task is to calculate the average of all the positive numbers in the array. Problem Description The goal is to compute the average of all positive numbers in a given array. This involves summing up the positive numbers and dividing the sum by the count of positive numbers. Example 1 Input: ...
Read MoreJavaScript program to generate all rotations of a number
In this article, we will learn to generate all rotations of a number in JavaScript. A rotation involves moving the first digit to the end of the number, creating all possible circular arrangements of the digits. Problem Statement Given a number, we need to generate all possible rotations of its digits. A rotation is defined as moving the first digit to the end of the number. Input: 123 All Rotations: 123 (original number) 231 (first rotation: move 1 to the end) 312 (second ...
Read MoreJavaScript program to count triplets with sum smaller than a given value
In this article, we will learn to count triplets with a sum smaller than a given value in JavaScript. Triplets in an array whose sum is less than a provided number is a popular problem in competitive coding and algorithm design. Problem Statement Given an array of integers and a target sum, we need to find the number of triplets (a, b, c) where the sum of three elements is less than the given value. Input: const arr = [5, 1, 3, 4, 7]; const sum = 12; Output: 4 ...
Read MoreJavaScript Program to Find Perimeter of a Triangle
The perimeter of a triangle is the sum of the lengths of its three sides. You can find the perimeter of a triangle using JavaScript by calculating the sum of all sides, where perimeter = a + b + c. To find the perimeter of a triangle using JavaScript, we need to write a function that adds the three side lengths together. In this article, we will understand the perimeter formula and implement practical examples. Understanding the Perimeter Formula The formula for the perimeter of a triangle is straightforward. The perimeter equals the sum of all three ...
Read MoreJavaScript Program to Find Area and Perimeter of Rectangle
To find the area and perimeter of a rectangle in JavaScript, we use the basic formulas for rectangle calculations. The area of a rectangle is the multiplication of its length by its breadth, and the perimeter is the sum of all four sides. In this article, we'll understand the formulas and implement practical JavaScript examples to calculate rectangle area and perimeter. Understanding the Formulas The formulas for rectangle calculations are straightforward: Area = length × breadth Perimeter = 2 × (length + breadth) ...
Read MoreJavaScript program to find Number of Squares in an N*N grid
A grid is a 2-dimensional arrangement of squares divided into rows and columns. From a given N*N square grid we have to calculate the total number of squares possible. There are multiple ways to find the number of squares in a given grid. In this article, we are going to learn about various approaches for calculating the number of squares in a given grid of size N*N. Understanding the Problem In an N×N grid, we can form squares of different sizes. For example, in a 4×4 grid, we can have: 1×1 squares: 16 ...
Read More