JavaScript Program for the Least Frequent Element in an Array

Prabhdeep Singh
Updated on 15-Mar-2026 23:19:01

796 Views

In this program, we are given an array of integers and need to return the element that appears the least number of times. If multiple elements have the same minimum frequency, we can return any one of them. Problem Statement Given an array with duplicate numbers, we need to count the occurrence of each element and return the one with the least frequency. If multiple elements have the same minimum frequency, any one can be returned. Example 1: Input: [1, 3, 3, 5, 5, 4, 4, 4] Output: 1 Explanation: 1 appears 1 time, 3 ... Read More

Robotics: Building Autonomous Robots with Raspberry Pi and JavaScript

Mukul Latiyan
Updated on 15-Mar-2026 23:19:01

646 Views

In recent years, the world of robotics has seen a significant shift towards open-source technologies and platforms. One such platform that has gained immense popularity is Raspberry Pi, a small and affordable single-board computer. Coupled with the power and versatility of JavaScript, developers can now embark on exciting journeys into the world of robotics. In this article, we will explore how to build autonomous robots using Raspberry Pi and JavaScript, diving into code examples, explanations, and their output. Setting Up Raspberry Pi Before we delve into the realm of JavaScript robotics, it is essential to set up our ... Read More

How to Hide an HTML Element by Class using JavaScript?

Mrudgandha Kulkarni
Updated on 15-Mar-2026 23:19:01

9K+ Views

When working with dynamic web pages, it's often necessary to hide certain HTML elements based on specific conditions or user interactions. One common approach is to assign classes to these elements and then dynamically hide them using JavaScript. This provides a flexible and efficient way to control the visibility of elements without modifying the HTML structure. In this article, we will explore how to hide HTML elements by class using JavaScript. We'll discuss different methods to select elements by class and demonstrate practical techniques for hiding and showing elements dynamically. Methods for Selecting Elements by Class JavaScript ... Read More

How to create an id using mongoose in Javascript?

Shubham Vora
Updated on 15-Mar-2026 23:19:01

4K+ Views

In this tutorial, we will learn to create an id using mongoose in JavaScript. Users can use the Mongoose NPM package in NodeJS to use MongoDB with NodeJS or connect MongoDB with the application. While storing the data in the MongoDB database, we must add a unique id to every data collection. However, if we don't add an id, it generates automatically and adds to the data. Syntax Users can follow the syntax below to create an id using mongoose in JavaScript. var newId = new mongoose.mongo.ObjectId(); In the above syntax, we access ... Read More

JavaScript Program to Find a triplet that sum to a given value

Alshifa Hasnain
Updated on 15-Mar-2026 23:19:01

635 Views

In this article, we will learn to find three numbers in an array that add up to a given sum value using JavaScript. We are going to write a JavaScript program to find a triplet that sums up a given value. This program will make use of nested loops to iterate over the input array and check for the existence of a triplet with a sum equal to the given value. We'll present two different approaches and analyze their implementations. Sorting and Two-Pointer Technique The first approach uses sorting and the two-pointer technique to solve the problem efficiently. ... Read More

JavaScript Program for Left Rotation and Right Rotation of a String

Shriansh Kumar
Updated on 15-Mar-2026 23:19:01

1K+ Views

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 More

JavaScript Program for Longest Subsequence of a Number having Same Left and Right Rotation

Prabhdeep Singh
Updated on 15-Mar-2026 23:19:01

291 Views

We will implement a code to find the longest subsequence of a given number that has the same left and right rotation in JavaScript. Left rotation moves the leftmost digit to the rightmost position, while right rotation moves the rightmost digit to the leftmost position. Understanding the Problem Given a number, we need to find a subsequence (formed by deleting some digits) where left and right rotations produce the same result. For example: Single digit sequences always have equal rotations: 1, 2, 3 Two identical digits: 11, 22, 33 Alternating patterns of even length: 1010, 2323, ... Read More

JavaScript Program for Diagonally Dominant Matrix

Ravi Ranjan
Updated on 15-Mar-2026 23:19:01

345 Views

A diagonally dominant matrix is a square matrix where the absolute value of each diagonal element is greater than or equal to the sum of absolute values of all other elements in that row. In this article, we'll write a JavaScript program to check if a given matrix is diagonally dominant. This requires understanding 2D arrays, nested loops, and conditional statements. Diagonally Dominant Matrix Example ... Read More

JavaScript Program to Find Area and Perimeter of Rectangle

Disha Verma
Updated on 15-Mar-2026 23:19:01

9K+ Views

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 More

JavaScript Program for Markov Matrix

Prabhdeep Singh
Updated on 15-Mar-2026 23:19:01

290 Views

A matrix is a kind of 2-D array, which is in the form of some number of rows, and for each row, there is the same number of columns and by the row and column number, we can get the element at any particular index. For the Markov matrix, each row's sum must equal 1. We are going to implement a code to create a new Markov matrix and find if the currently given matrix is a Markov matrix or not. What is a Markov Matrix? A Markov matrix is a special type of matrix where each row ... Read More

Advertisements