Found 6710 Articles for Javascript

JavaScript Program To Delete Nodes Which Have A Greater Value On Right Side

AmitDiwan
Updated on 13-Mar-2023 16:42:33

301 Views

We will be implementing a function to delete nodes in a linked list which have a greater value on their right side. The approach is to traverse the linked list from right to left and keep track of the maximum value encountered so far. For each node, we will compare its value with the maximum value and delete the node if its value is less than the maximum value. This way, all the nodes with values greater than the maximum value on their right side will be deleted. Approach The approach to delete nodes which have a greater value on ... Read More

JavaScript Program To Delete Alternate Nodes Of A Linked List

AmitDiwan
Updated on 13-Mar-2023 16:34:29

229 Views

We will be writing a JavaScript program to delete alternate nodes of a linked list. We will be utilizing a while loop to traverse the linked list while keeping a track of the current and previous node. In each iteration of the loop, we will be skipping the current node and linking the previous node directly to the next node, effectively deleting the current node from the list. This process will be repeated until all the alternate nodes have been deleted from the linked list. Approach Traverse the linked list from head to end. For every node, store ... Read More

JavaScript program to count triplets with sum smaller than a given value

Alshifa Hasnain
Updated on 06-Mar-2025 19:22:19

445 Views

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). For exampleInput const arr = [5, 1, 3, 4, 7]; const sum = 12;Output 4 Explanation: The valid triplets are :(1, 3, 5)(1, 3, 4)(1, 4, 5)(1, 3, 7), all having a sum of less than 12. ... Read More

JavaScript Program to Count rotations which are divisible by 10

AmitDiwan
Updated on 13-Mar-2023 16:28:44

275 Views

We are going to write a program in JavaScript that counts the number of rotations of a given number which are divisible by 10. We will loop through the rotations of the number and check if each one is divisible by 10. If a rotation is divisible, we will increment our count. In the end, we will return the count as the result of our program. This program will be useful in various applications as it provides a simple solution to check the divisibility of a number by 10. Approach The approach to solve this problem is as follows − ... Read More

JavaScript Program to Count rotations required to sort given array in non-increasing order

AmitDiwan
Updated on 13-Mar-2023 16:24:04

167 Views

We will be writing a program to count the number of rotations required to sort an array in non-increasing order. The program will use a loop to traverse the array and keep track of the maximum element found so far. When a smaller element is found, we will increment the rotation count and update the maximum element. In the end, the rotation count will be returned as the result of the program. This program will help us efficiently sort the array and determine the number of rotations required to achieve a non-increasing order. Approach The approach to counting rotations required ... Read More

Get the relative timestamp difference between dates in JavaScript

Rushi Javiya
Updated on 10-Mar-2023 16:53:36

6K+ Views

Have you ever seen notifications on any website showing the time stamp? It shows something like “12 minutes ago”, “2 days ago”, “10 hours ago”, etc. It is related to the timestamp difference between two dates or times. Also, some apps show that this device's last login was 22 hours ago. So, there are many uses to get the timestamp difference between two dates. In this tutorial, we will learn different approaches to get the relative timestamp difference between two dates. Use the getTime() method with the date and create a custom algorithm In JavaScript, we can ... Read More

How to check input file is empty or not using JavaScript/jQuery?

Rushi Javiya
Updated on 10-Mar-2023 16:52:40

9K+ Views

In JavaScript, while working with the form elements, we need to validate the input fields and form elements when a user enters the value. In this tutorial, we will work with the file input. We will also learn to validate the file input. Sometimes, we may be required to check if the file is selected in the input field, then only enable the submit button; otherwise, disable the submit button. So, it will not allow users to submit the form or file without selecting it. Validate the file input using JavaScript In JavaScript, we can access the file input ... Read More

How to check if the clicked element is a div or not in JavaScript?

Rushi Javiya
Updated on 10-Mar-2023 16:51:11

9K+ Views

Have you ever worked with the modal or seen it on any website? When you click outside the modal, it closes the modal. We must detect whether users have clicked on or outside the modal element in such cases. If users click outside the modal element, we need to close the modal element. In this tutorial, we will learn different ways to detect the click on the div element. Use the onClick attribute to check if the clicked element is a div In HTML, we can add the onClick attribute to any HTML element and assign it the ... Read More

How to check if the string contains only digits in JavaScript?

Rushi Javiya
Updated on 10-Mar-2023 16:48:05

7K+ Views

We may require to find the string, which contains only digits but not any other characters while developing. The easiest way to check can parse the numbers from the string and compare its length with the original string’s length. If both are the same, that means the string contains only digits. Users can use the parseInt() method to parse the numbers from the string. However, in this tutorial, we will learn other methods to check if the string contains only digits in JavaScript. Use the for-loop and CharCodeAt() method We can iterate through the string using the for-loop. ... Read More

How to check if one date is between two dates in JavaScript?

Rushi Javiya
Updated on 10-Mar-2023 16:44:52

2K+ Views

In JavaScript, we can use the Date() object to create different timestamps. Also, we may be required to check if one date is between two using JavaScript. For example, we want to create a filter for orders in the eCommerce application based on the dates. So, we should be able to filter all orders between the two dates that users enter into the date input field. Another real-world use case of checking one date between two is in the banking application. For example, while developing the banking system application, developers need to create a filter allowing users to ... Read More

Advertisements