Javascript Articles

Page 21 of 534

JavaScript Program to Count Inversions of size three in a given array

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 272 Views

In this tutorial, we will learn to count inversions of size three in a given array. An inversion of size three is a triplet of indices (i, j, k) where i < j < k but arr[i] > arr[j] > arr[k]. Problem Statement: Given an array of length n containing different numeric entries, we need to find the total number of triplets (i, j, k) such that arr[i] > arr[j] > arr[k], where i < j < k. We'll explore two approaches: a brute force method and an optimized solution using nested loops. Using the Brute Force ...

Read More

JavaScript Program to Count Rotations Divisible by 4

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 308 Views

In this tutorial, we will learn to count the total number of rotations divisible by 4 for the given number. Problem statement − We have given a number value. We need to rotate numbers in clockwise or anti-clockwise directions and count the total number of rotations divisible by 4. Here, we will learn two different approaches to counting rotations divisible by 4. Understanding Number Rotation When we rotate a number, we move digits from one position to another. For example, rotating 1234 clockwise gives us: 4123, 3412, 2341, and back to 1234. Each rotation creates a ...

Read More

JavaScript Program to Count Rotations Divisible by 8

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 286 Views

In this tutorial, we'll learn how to count the number of rotations of a given number that are divisible by 8. A rotation means moving digits from one end to another - for example, rotating 123 gives us 231, 312, and back to 123. We'll explore two different approaches: the straightforward rotation method and an optimized approach using divisibility rules. Understanding Number Rotation When we rotate a number, we take the last digit and move it to the front. For example, rotating 1234 gives us these possibilities: 1234 (original) 4123 (moved 4 to front) 3412 (moved ...

Read More

JavaScript Program to check idempotent matrix

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 240 Views

An idempotent matrix is a square matrix that has the same number of rows and columns and when we multiply the matrix by itself the result will be equal to the same matrix. We will be given a matrix and we have to find that whether it is an idempotent matrix or not. Mathematical Definition If the given matrix is M, then for M to be an idempotent matrix it should follow the property: M * M = M Matrix Multiplication Overview Multiplication of a matrix with another matrix produces another matrix and ...

Read More

How To Modify This JavaScript Code To Grab An Image URL From A JSON File, And Display It In HTML?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 10K+ Views

This can be done by using the JavaScript method JSON.parse() to parse through the JSON file and extract the URL of the desired image. Then, an HTML img tag can be created with a source attribute set to this URL. Finally, this img tag can be appended to an existing HTML element in order to display it on your page. This will require some knowledge of basic JavaScript syntax, as well as familiarity with how JSON is structured and parsed within it. With these skills in hand, you should have no trouble modifying your code to achieve your goal! ...

Read More

JavaScript Program to Check If a Singly Linked List is Palindrome

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 380 Views

A singly linked list is a linear data structure that is stored in a non-contiguous way in the memory and each block is connected by holding the address of the next block also known as a node. A palindrome can be explained as a set of characters, digits, etc, and it reads the same from both the front and backside. We will be given a singly linked list and have to find whether the values stored at the nodes are equal from both the front and backside. Problem Examples Input 1 -> 2 -> 3 -> 3 ...

Read More

JavaScript Program for Ceiling in a sorted array

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 285 Views

An array is a linear data structure that contains objects, and in a sorted array, elements are arranged in increasing order. Given a sorted array and an integer x, we need to find the ceiling of x. The ceiling is the smallest element in the array that is greater than or equal to x. If no such element exists, we return that the ceiling does not exist. Problem Understanding Let's understand this with examples: Example 1 Array = [1, 3, 5, 7, 9] X = 19 Output: Ceiling does not exist (no element ≥ ...

Read More

JavaScript Program for Check if an array is sorted and rotated

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 366 Views

A sorted array is an array where all the elements are present in increasing order. We have given an array of size N and an array containing the distinct integers (which means every integer is present only one time). We have to check the array is sorted and rotated in a clockwise direction. Here we have to return 'YES' if the array is sorted and rotated otherwise, we have to return 'NO'. Note − Here we are talking about the sorted and rotated means at least one rotation should be present. We cannot consider a sorted array as a ...

Read More

How To Show Only One V-Menu At A Time When Clicking To Show The Menu?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 1K+ Views

In Vuetify applications, showing only one v-menu at a time when clicking requires proper state management. This prevents multiple menus from being open simultaneously and provides better user experience. Understanding v-menu Behavior By default, v-menu components can open independently. To ensure only one menu is visible at a time, we need to control their state using Vue's data properties and watchers. Method 1: Using Individual State Control This approach manages each menu's state individually and closes others when one opens: ...

Read More

How to Use Conditional Statements On Objects?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 932 Views

Conditional statements allow you to execute different code blocks based on object properties and values. In JavaScript, you can use if, if-else, and switch statements to make decisions based on object data. This article demonstrates how to apply conditional logic to JavaScript objects, checking their properties and values to control program flow. Using if Statement with Objects The if statement executes code when a condition evaluates to true. You can check object properties, existence, or values. Syntax if (condition) { // code to execute if condition is true } ...

Read More
Showing 201–210 of 5,340 articles
« Prev 1 19 20 21 22 23 534 Next »
Advertisements