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
What is difference between Microtask Queue and Callback Queue in asynchronous JavaScript?
In asynchronous JavaScript, there are two ways to schedule tasks – microtask queue and callback queue. Both queues are handled differently by the JavaScript engine, with microtasks having higher priority than callbacks. Event Loop Overview The event loop processes tasks in this order: call stack → microtask queue → callback queue. Understanding this priority system is crucial for predicting execution order in asynchronous code. Call Stack (Synchronous) Highest Priority Microtask Queue ...
Read MoreHow to send row data when clicking the button using javascript?
When working with HTML tables, you often need to access row data when a user clicks a button. This is useful for editing, deleting, or sending data to a server. We'll explore two methods: vanilla JavaScript and jQuery. Using JavaScript to Access Row Data In this approach, we access the clicked button element, traverse up to find its parent row, then extract all column data from that row. Syntax var clickedRow = clickedElement.parentNode.parentNode.id; var rowData = document.getElementById(clickedRow).querySelectorAll('.column-data'); let text = rowData[0].innerHTML; The clickedRow contains the row ID, rowData contains all columns, and we ...
Read MoreBuilding frequency map of all the elements in an array JavaScript
Building a frequency map (also called a frequency counter) is a common programming task that helps count how many times each element appears in an array. This technique is useful for data analysis, finding duplicates, or solving algorithmic problems. A frequency map returns an object where each unique element from the array becomes a key, and its corresponding value represents how many times that element appears. Basic Approach Using forEach() The most straightforward method is to iterate through the array and build an object that tracks the count of each element: const arr = [2, ...
Read MoreGreatest element in a Multi-Dimensional Array in JavaScript
We have to write a simple function in JavaScript that takes in an array of Numbers (nested to any level) and return the greatest number present in the array. Problem Example If the input array is: const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], ...
Read MoreJavaScript - Finding the third maximum number in an array
In this article, we will learn to find the third maximum unique number in an array of JavaScript, or the largest number if there are fewer than three unique values. We will be using three methods: a single-pass approach for efficiency, a sorting method to identify the number after removing duplicates, and a combination of Set and Max-Heap for optimal handling of large datasets. Problem Statement Given an array of integers, find the third maximum unique number. If the array contains fewer than three unique numbers, return the largest number in the array. Input: const nums = ...
Read MoreRemove all occurrences of a multiple occurring element in an array in JavaScript
We are required to write a JavaScript function that takes in an array of literal values. The array might contain some repeating values. Our function should remove all the values from the array that are repeating. We are required to remove all instances of all such elements. Problem Understanding When an element appears multiple times in an array, we want to remove ALL occurrences of that element, not just the duplicates. For example, if 2 appears twice, we remove both instances. Using filter() with indexOf() and lastIndexOf() The most efficient approach uses filter() to keep only ...
Read MoreRearranging array elements in JavaScript
JavaScript function that takes in an array of literals, arr, as the first and the only argument. This array contains some duplicates placed adjacently. Our function should rearrange the elements of the array such that no two elements in the array are equal. Our function should return the rearranged array, given that it's guaranteed that there exists at least one possible way of such arrangement. Problem Example For example, if the input to the function is: const arr = [7, 7, 7, 8, 8, 8]; Then the output should be: const ...
Read MoreZig-Zag pattern in strings in JavaScript?
We need to write a function that reads a string and converts the odd indexed characters in the string to upperCase and the even ones to lowerCase and returns a new string. Understanding the Pattern A zig-zag pattern alternates between lowercase and uppercase characters based on their index position. Even indices (0, 2, 4...) become lowercase, while odd indices (1, 3, 5...) become uppercase. Example Implementation const text = 'Hello world, it is so nice to be alive.'; const changeCase = (str) => { const newStr = str ...
Read MoreRemoving duplicates and inserting empty strings in JavaScript
We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end. Problem Description If we find 4 duplicate values we have to remove them all and insert four empty strings at the end. This maintains the original array length while eliminating duplicates. How It Works The algorithm uses reduce() to iterate through the array. For each element, it checks if the current index matches the last occurrence using lastIndexOf(). If yes, it's the final occurrence and gets added to the ...
Read MoreLength of longest string chain in JavaScript
A word chain problem involves finding sequences of words where each word can be formed by adding exactly one character to the previous word. This is a classic dynamic programming problem that requires checking predecessor relationships and building chains efficiently. Understanding Word Chains A word1 is a predecessor of word2 if we can add exactly one letter anywhere in word1 to make it equal to word2. For example, "abc" is a predecessor of "abac" because we can insert 'a' at position 2. A word chain is a sequence of words [word_1, word_2, ..., word_k] where each word ...
Read More