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 on Trending Technologies
Technical articles with clear explanations and examples
How to run functions iteratively with async await in JavaScript?
Running functions iteratively with async/await allows you to execute asynchronous operations in sequence within loops. This is useful when you need to process items one by one rather than concurrently. Basic Syntax async function iterativeFunction() { for (let i = 0; i < count; i++) { await asyncOperation(); } } Example: Sequential Function Calls async function test(i) { while (i { setTimeout(() => { ...
Read MoreHow to find the second largest element in a user-input JavaScript array?
Finding the second largest element in a JavaScript array requires comparing elements and tracking the two highest values. Here are several approaches to accomplish this task. Method 1: Using Single Pass Iteration This approach iterates through the array once, maintaining variables for the largest and second largest elements: var numbers = [10, 50, 80, 60, 89]; var firstLargerNumber = Number.MIN_SAFE_INTEGER; var secondlargerNumber = firstLargerNumber; for(var tempNumber of numbers){ if(tempNumber > firstLargerNumber){ secondlargerNumber = firstLargerNumber; firstLargerNumber ...
Read MoreCheck Disarium number - JavaScript
A Disarium number is a number where the sum of its digits raised to their respective positions equals the original number. Definition For a number with digits xy...z, it's a Disarium number if: xy...z = x^1 + y^2 + ... + z^n Where n is the total number of digits in the number. Example Let's check if 175 is a Disarium number: 175 = 1^1 + 7^2 + 5^3 = 1 + 49 + 125 = 175 Since the sum equals the original number, 175 is a Disarium ...
Read MoreHow to perform integer division and get the remainder in JavaScript?
In JavaScript, performing integer division and getting the remainder requires different operators than regular division. The division operator (/) returns a floating-point result, while the remainder operator (%) gives you what's left after division. The remainder operator (%) returns the remainder when one operand is divided by another. It always takes the sign of the dividend (the first operand). For the operation x % y, x is the dividend and y is the divisor. Understanding Division vs Remainder Regular division in JavaScript returns decimal results, but for integer division, we need to use Math.floor() or other methods ...
Read MoreFlexbox layout losing proportions when reduced in size
Flexbox items can lose their intended proportions when the container shrinks, causing layout distortion. This happens due to default flex shrinking behavior and minimum size calculations. The Problem By default, flex items have flex-shrink: 1 and min-width: auto, which can cause unexpected shrinking behavior when the container becomes smaller than the content. Item 1 with long content Item 2 Item 3 .flex-container { display: flex; width: 300px; border: 1px solid #ccc; } .flex-item { flex: 1; ...
Read MoreAlign the text of a document with CSS
The text-align property in CSS is used to align the text content within an element. It accepts several values: left (default), right, center, and justify. Syntax text-align: left | right | center | justify; Values left: Aligns text to the left edge (default) right: Aligns text to the right edge center: Centers the text horizontally justify: Spreads text evenly across the width, aligning both left and right edges Example Here's how to use different text alignment values: ...
Read MoreJavaScript Remove non-duplicate characters from string
Non-duplicate characters in a string are those that appear only once and do not repeat within the string. Sometimes in JavaScript, we need to work with strings and manipulate them based on certain conditions. One common task is to remove characters that only appear once in a string, keeping only the characters that appear more than once. In this article, we will understand how to remove non-duplicate characters from a string in JavaScript. Understanding the Problem Suppose we have a string like "teeth_foot". We want to remove all characters that appear only once, keeping only characters that appear multiple ...
Read MoreHow to set div position relative to another div in JavaScript?
Setting div position relative to another div in JavaScript can be achieved through several methods including CSS positioning, Flexbox, and dynamic JavaScript positioning. Here are the most effective approaches. Method 1: Using CSS Positioning The most common approach uses CSS position: relative and position: absolute to position elements relative to each other. Relative Positioning .parent-div { ...
Read MoreHow to split string when the value changes in JavaScript?
To split a string when the character value changes in JavaScript, you can use the match() method with a regular expression that captures consecutive identical characters. Syntax string.match(/(.)\1*/g) How the Regular Expression Works The pattern /(.)\1*/g breaks down as: (.) - Captures any single character \1 - Matches the same character as captured in group 1 * - Matches zero or more of the preceding element g - Global flag to find all matches Example var originalString = "JJJJOHHHHNNNSSSMMMIIITTTTHHH"; var regularExpression = /(.)\1*/g; console.log("The original string = ...
Read MoreProgram to pick out duplicate only once - JavaScript
We have an array of literals that contains some duplicate values appearing for many times like this: const arr = [1, 4, 3, 3, 1, 3, 2, 4, 2, 1, 4, 4]; We are required to write a JavaScript function that takes in this array and pick out all the duplicate entries from the original array and only once. So, for the above array, the output should be: [1, 4, 3, 2] Method 1: Using indexOf and lastIndexOf This approach checks if an element's first and last occurrence positions are ...
Read More