Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Prabhdeep Singh
Page 8 of 17
How to return the background color of an element with JavaScript DOM?
In this tutorial, we will explore how to get and set the background color of an element using JavaScript DOM. The style.backgroundColor property allows us to both retrieve and modify background colors dynamically. Browser Support Chrome Browser − Version 1.0 and above. Edge Browser − Version 12 and above. Internet Explorer − Version 4.0 and above. Firefox Browser − Version 1.0 and above. Safari Browser − Version 1.0 and above. Opera Browser − Version 3.5 and above. Syntax ...
Read MoreHow to secure my JavaScript using "Strict mode"?
In this tutorial, we are going to learn how to secure my JavaScript using "Strict mode". There are some errors in the code which are just ignored by the JavaScript engine and if any line fails it performs nothing. To indicate that there is an error we can use strict mode which will make the JavaScript engine throw an error. The 'use strict' is a literal expression which is a directive we can add to the code. We can add this 'use strict' directive to the whole script, a function, or a class. Syntax Now let's see ...
Read MoreHow to set JavaScript Cookie with no expiration date?
In this tutorial, we will learn how to set JavaScript cookies with no expiration date. Cookies are small data files stored by web browsers that help websites remember user preferences and track behavior. When a cookie has no expiration date, it becomes a session cookie that lasts until the browser is closed. Understanding Cookie Expiration The expires attribute in JavaScript cookies is optional. If you don't specify an expiration date, the cookie will automatically expire when the browser session ends (when the user closes the browser). This type of cookie is called a session cookie. Syntax for ...
Read MoreHow to replace all occurrences of a string in JavaScript?
In JavaScript, there are several methods to replace all occurrences of a substring within a string. This tutorial covers three effective approaches: using split() and join(), regular expressions with replace(), and the modern replaceAll() method. Using split() and join() This method splits the string at each occurrence of the target substring, then joins the parts back together with the replacement string. Syntax const given_string = "original string"; const to_replace = "substring to find"; const replacement = "replacement string"; const string_after_splitting = given_string.split(to_replace); const required_string = string_after_splitting.join(replacement); Example ...
Read MoreC Program to Find Minimum Insertions to Form a Palindrome
A palindrome is a string that reads the same forwards and backwards. Given a string, we need to find the minimum number of character insertions required to make it a palindrome. We will explore three approaches − recursive, memoization, and dynamic programming. Syntax int minInsertions(char str[], int start, int end); Method 1: Recursive Approach The recursive approach compares characters from both ends. If they match, we move inward; otherwise, we try inserting at either end and take the minimum ? #include #include #include int findMin(int a, int b) ...
Read MorePHP Program for Converting Roman Numerals to Decimal Lying Between 1 to 3999
Roman numerals are characters used in a numeric notation system based on the ancient Roman system. In this tutorial, we'll convert Roman numeral strings to decimal values in the range 1 to 3999. Roman Numeral System Roman numerals follow descending order but use subtractive notation to avoid four consecutive characters. Here are the main symbols − SYMBOL VALUE M 1000 CM 900 D 500 CD 400 C 100 XC 90 L 50 XL 40 X 10 ...
Read MorePHP Program to Check if all rows of a matrix are circular rotations of each other
A rectangular array called a matrix is made up of rows and columns. And circular rotations entail rotating the array's elements so that after one rotation, the last member is in the first position and the other elements are shifted to the right. We are given an N*N matrix in this problem, and our objective is to determine whether all of the rows are circular rotations of one another. If they are, print "YES, " otherwise print "NO." In order to better understand the issue, let's look at some cases with explanations below. Input 1 mat ...
Read MoreJava program to find longest common prefix using word by word matching
In this article, we will explore how to find the longest common prefix among a given set of strings using two different approaches in Java. We will first discuss an approach that compares all strings directly to find the longest prefix and then move to a word-by-word matching approach. Problem Statement We are given a set of strings and we have to find the common prefix among all of them. A prefix is a substring for a string that contains the zero index and could be of any length from 1 to a complete string. Input 1 string arr[] = ...
Read MoreJava program to find length of the longest substring without repeating characters
In Java, substrings are part of the string which contains the continuous character of the string of any length from 1 to complete string. We are given a string and we have to find the length of the largest substring from the given string that only contains the unique characters. We will see three types of methods: finding every substring, sliding windows, and two-pointers. Problem Statement Given a string, write a Java program to find length of the longest substring without repeating characters − Input thisisthegivenstring Output The length of the longest substring that contains only unique characters is: ...
Read MoreSort 1 to N by swapping adjacent elements
An array is a linear data structure that stores the elements and a sorted array contains all the elements in increasing order. Sorting an array by swapping the adjacent elements means we can swap the adjacent elements any number of times and we have to sort the array. We will be given two array’s first array is the array to be sorted and another array is a Boolean array that represents whether the current element is swappable or not. If the given array is of the length N then all the elements present will be from 1 to N. ...
Read More