Found 8591 Articles for Front End Technology

JavaScript Program to Check If a Singly Linked List is Palindrome

Prabhdeep Singh
Updated on 20-Apr-2023 17:19:55

306 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. Input 1 -> 2 -> 3 -> 3 -> 2 -> 1 ... Read More

JavaScript Program to Check if a Matrix is Symmetric

Prabhdeep Singh
Updated on 12-Dec-2024 12:22:52

631 Views

To check if a matrix is symmetric, we simply check if the matrix and it's corresponding transpose matrix are equal. A symmetric matrix is a special case of a matrix where both the matrix and the transpose of the matrix are the same (A = A^T). In this article we are given with an array and our task is to write a JavaScript program to check if a matrix is symmetric. Users must be familiar with 2D matrix, transpose of matrix, symmetric matrix, nested loop and if/else statement. Example Input: matrix [A]: [[1, 2, ... Read More

JavaScript Program to Check if a Given Matrix is Sparse or Not

Prabhdeep Singh
Updated on 15-Dec-2024 16:29:10

258 Views

To check if a given matrix is sparse or not, we will be discussing two different approaches, their complexities, and example codes. A sparse matrix is a special type of matrix in which the number of zeroes is strictly more than half of the the total number of elements present in the given matrix. In this article we are having a 2D matrix, our task is to write a JavaScript program to check if a given matrix is sparse or not. Users must be familiar with conditional statement, nested for loop and javascript methods. Example Input: Matrix: [[1, ... Read More

JavaScript Program to check idempotent matrix

Prabhdeep Singh
Updated on 20-Apr-2023 17:16:20

178 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. Mathematically − If the given matrix ix M, then of M to be an idempotent matrix is should follow the property − M*M = M Multiplication of Matrix Multiplication of a matrix with another matrix produces another matrix and if the given matrix is the square ... Read More

JavaScript Program to Count Rotations Divisible by 8

Shubham Vora
Updated on 20-Apr-2023 17:02:54

195 Views

Problem Statement − We have given a number. We need to rotate the number and need to find the total number of rotations divisible by 8. Here, we will learn two different approaches to counting rotations divisible by 8. Rotate the Number and Check if Rotation is Divisible by 8 The first approach is to rotate numbers and get every possible rotation one by one. Also, check if rotation is divisible by 8. If yes, add 1 to the count. Syntax Users can follow the syntax below to count rotations divisible by 8 by rotating the numbers. for ( ) ... Read More

JavaScript Program to Count Rotations Divisible by 4

Shubham Vora
Updated on 20-Apr-2023 17:02:19

213 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. Rotate the Number and Check if it is Divisible by 4 In this approach, we will convert the number to a string first. We can make n rotations for the string of length n. We will remove the ... Read More

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

Shubham Vora
Updated on 20-Apr-2023 17:00:45

190 Views

In this tutorial, we will learn to count inversions of size three in a given array. Problem statement − We have given an array of length n containing the different numeric entries. We need to find the total number of pairs of numbers of size 3 such that arr[i] > arr[j] > arr[k], where I < j < k. Here, we will learn the brute force approach first and after that, we will optimize its time and space complexity. Using the Brute Force Approach In the brute force approach, we will use three nested for loops to find a count ... Read More

JavaScript Program to Check whether a Given Number is Power of 2

Shubham Vora
Updated on 03-Dec-2024 14:37:26

3K+ Views

To check whether a given number is power of 2 in JavaScript, we can check if the number is generated using multiplying 2's only. We will be discussing 5 different approaches to check whether a given number is a power of 2. In this article we are having two numbers, our task is to check whether a given number is power of 2 in JavaScript. Users must be familiar with JavaScript Math functions, loops, binary representation and bitwise operators. Approaches to Check if a Number is Power of 2 Here is a list of approaches to check whether ... Read More

How to conditionally add a member to an object using JavaScript?

Shubham Vora
Updated on 20-Apr-2023 16:32:29

3K+ Views

The object is the most important data type of JavaScript. Even everything is an object in JavaScript. For example, Array is an object, and Number, String, and Boolean can also be an object. Sometimes, developers require to insert properties into the object based on some condition. For example, we have an object of the person, and we only require adding the driving licence property if a person is 18 years old. Here, we will learn different approaches to adding a member to an object using JavaScript conditionally. Using the Spread Operator to add a Member to an Object Conditionally The ... Read More

How to Get Value of Selected Radio Button Using JavaScript?

Yaswanth Varma
Updated on 22-Nov-2024 11:06:00

9K+ Views

To get value of selected radio button using JavaScript is useful to a user in various ways such as collecting surveys data, in quiz or dynamic UI updates like changing to dark or light theme. We will be discussing two approaches to get the selected radio button value. In this article, we are having three radio buttons with their labels and our task is to get value of selected radio button using JavaScript. Approaches to Get Value of Selected Radio Button Here is a list of approaches to get value of selected radio button using JavaScript which we will be ... Read More

Advertisements