Found 6685 Articles for Javascript

JavaScript Program to Check if it is possible to sort the array after rotating it

Prabhdeep Singh
Updated on 13-Apr-2023 15:28:38

57 Views

Rotating an array means moving the elements of each index (excluding one end ) to the following index for the right rotation and the previous index for the left rotation. For the right rotation zeroth index takes the value of the last index and vice-versa for the left rotation. Sort an array means that all the elements are in the proper increasing order. We will implement the proper code with an explanation and time, and space complexity discussion. Example Input: 5 6 9 10 2 3 3 4 Output: Yes Explanation: We can rotate the given array 4 times ... Read More

JavaScript Program to Check if it is possible to make array increasing or decreasing by rotating the array

Prabhdeep Singh
Updated on 13-Apr-2023 15:27:24

85 Views

Rotation of the array means to assume the array as a circular array and rotate the elements of the array to either their left or right direction by one index at each rotation and the element at one end may take the value present at another end. An Increasing array means that each element will be greater than or equal to its previous element and decreasing array means each element will be less than or equal to the previous element. In this problem, we are given an array and we can rotate the array in either the left or the ... Read More

JavaScript Program to Check if all rows of a matrix are circular rotations of each other

Prabhdeep Singh
Updated on 13-Apr-2023 15:26:25

124 Views

Matrix is a kind of 2-D array in which there is an array of fixed arrays that defines the rows and for each index of this array there are fixed length arrays present and the length of these arrays defines the number of columns present in the matrix. We can store any kind of data type in these cells provided by the matrix. We will be provided with a matrix and each row contains some integers and we have to check if each row is the rotation of one another or not. Rotation of each other means by some number ... Read More

JavaScript Program to Check if all array elements can be converted to pronic numbers by rotating digits

Prabhdeep Singh
Updated on 13-Apr-2023 15:25:20

59 Views

Pronic numbers are also known as rectangular numbers, the pronic numbers are numbers that are multiples of two consecutive numbers. We will be given an array of integers and we can rotate the digits in any direction for a certain number of times to get all combinations. For any combination produced by rotating the digit if each array element can be converted into the pronic number then we will print true otherwise false. Pronic Numbers First, let us discuss pronic numbers: pronic numbers are the numbers that are the product of two consecutive numbers. Mathematically saying, if we have integer ... Read More

JavaScript Program to Check if a string can be formed from another string by at most X circular clockwise shifts

Prabhdeep Singh
Updated on 13-Apr-2023 15:24:08

104 Views

Circular clockwise shifts for the string mean rotating the characters of the string to their next character in alphabetic order. For each circular shift characters are converted to the next character and if there is no character present after the certain rotations (as ‘z’ is the last character of the English alphabet), then for that case we can assume characters in the cycle, and again start from the first character of English alphabets. We will be given two strings and we can rotate each character of the first string maximum of x numbers of times, and after doing a certain ... Read More

JavaScript Program for Rotate Doubly linked list by N nodes

Prabhdeep Singh
Updated on 13-Apr-2023 15:21:21

157 Views

A doubly linked list is a linear data structure where each node stores the address of the next and previous node. We have given a doubly linked list and we have to rotate the doubly linked list by N nodes and print it. Here N is the positive number and less than or equal to the count of the nodes present in the linked list. We are not given the specific side to rotate the doubly linked list. So we will rotate the doubly linked list in both ways. Rotating Doubly Linked List to Counter Clockwise We have to rotate ... Read More

JavaScript Program to Check if a string can be obtained by rotating another string by 2 places

Prabhdeep Singh
Updated on 13-Apr-2023 15:20:09

155 Views

We have given two strings s1 and s2 and we have to check if is it possible to obtain a string by rotating another string by 2 places. We can rotate the string either in an anti-clockwise or clockwise direction. Here we have to print ‘Yes’ if both the string got match after the rotation of the string by 2 places otherwise, we have to print ‘No’. Examples Let us assume we have given two strings s1 and s2 as Example 1 Input: s1 = “TutorialsPoint”, s2 = “PointTutorials” Output: No Explanation: here s2 is the anti-clockwise rotation of ... Read More

JavaScript Program to Check if a string can be obtained by rotating another string d places

Prabhdeep Singh
Updated on 13-Apr-2023 15:18:37

96 Views

Rotating a string means moving the characters of the string to their left or right side by one index and one end may contain the value stored at the other end. We will be given two strings and we have to rotate the second string either in the left or the right direction by given number (d) times and check if both strings are equal or not. We will write proper code with comments, explanations, and detailed discussions on the time and space complexity of the program. Examples If we have the given string ‘abcdef’ and the other string is ... Read More

How to select all links inside the paragraph using jQuery?

Tarun Singh
Updated on 13-Apr-2023 14:26:17

852 Views

jQuery is a popular JavaScript library that simplifies HTML DOM traversal, event handling, and AJAX interactions for rapid web development. It offers a wide range of built-in functions and methods that help developers to manipulate HTML elements, styles, and behaviors dynamically. In this article, we will see how to select all links inside a paragraph using jQuery. Selecting links inside a paragraph is a common requirement when we want to modify the links in a particular section of our website, such as changing styles, finding links, etc. How to select all links inside the paragraph? Selecting links inside the ... Read More

How to create an Asynchronous function in JavaScript?

Tarun Singh
Updated on 13-Apr-2023 14:28:39

2K+ Views

A JavaScript asynchronous function is a function that runs independently of the main flow of the program. This allows the program continues executing other code while the async function is running. Async is used to declare an async function, which runs asynchronously, and await is used to pause the execution of the function until a specific asynchronous task is achieved. Method to create an Asynchronous function Using async keyword The simplest way to create an asynchronous function is to use the async keyword before the function declaration. See the below syntax − Syntax async function fetchData() { ... Read More

Advertisements