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
Counting largest numbers in row and column in 2-D array in JavaScript
We are required to write a JavaScript function that takes in a two-dimensional array of integers as the only argument. The task of our function is to calculate the count of all such integers from the array that are the greatest both within their row and the column. The function should then return that count. For example − If the input array is − const arr = [ [21, 23, 22], [26, 26, 25], [21, 25, 27] ]; Then the output should be ...
Read MoreFind Smallest Letter Greater Than Target in JavaScript
Suppose we are given an array of sorted characters letters containing only lowercase letters. And given a target letter target. We are required to write a JavaScript function that takes in the array as the first argument and the letter as the second. The function is supposed to find the smallest element in the list that is larger than the given target. We have to keep in mind that letters also wrap around. For example, if the target is target = 'z' and letters = ['a', 'b'], the answer is 'a'. Problem Example If the input ...
Read MoreSwapping adjacent binary bits of a decimal to yield another decimal using JavaScript
Problem We are required to write a JavaScript function that takes in a number and swaps its adjacent binary bits to construct a new binary representation. The function should return the decimal equivalent of the modified binary. How It Works The algorithm converts the decimal number to binary, pairs adjacent bits, swaps each pair, and converts back to decimal. If the binary representation has an odd number of bits, we pad it with a leading zero to ensure complete pairs. Example Let's trace through number 13: 13 in binary: 1101 Pair adjacent bits: ...
Read Morecrypto.createECDH() Method in Node.js
The crypto.createECDH() method creates an Elliptic Curve Diffie-Hellman (ECDH) key exchange object using a predefined curve. ECDH is a cryptographic protocol that allows two parties to establish a shared secret over an insecure channel. Syntax crypto.createECDH(curveName) Parameters curveName - A string specifying the predefined elliptic curve to use. You can get available curves using crypto.getCurves(). Return Value Returns an ECDH object that can generate key pairs and compute shared secrets. Example 1: Basic ECDH Key Generation // Import the crypto module const crypto = require('crypto'); // ...
Read MoreExplain the importance of SafeViewArea in React Native?
The SafeAreaView component in React Native ensures your content displays within the safe boundaries of a device screen. It automatically adds padding to prevent content from being covered by system elements like the status bar, navigation bar, toolbar, and tab bars. While originally designed for iOS devices with notches and home indicators, it's now essential for modern app development across platforms. The Problem Without SafeAreaView When using regular View components, content can render underneath system UI elements, making it partially or completely hidden from users. Example: Text Overlapping Status Bar The following example shows how text ...
Read MoreHow to Create an Image Slider using HTML, CSS, and JavaScript?
In this article, we are going to create a slider carousel using JavaScript. Along with using JS we will be also using HTML and CSS for representation and defining the basic layout. A carousel is basically a collection of images represented as a slideshow that is used for displaying the images, text, or both in a cyclic manner. A slider Carousel is a special type of carousel that is specifically used for displaying the slider on a website's main page. This slideshow runs in a landscape mode. We can use the eventListener() provided by the JavaScript functions to ...
Read MoreWhat is the role of deferred scripts in JavaScript?
The defer attribute in JavaScript is a crucial performance optimization tool that controls when scripts execute during page loading. It ensures scripts run only after the HTML document has been completely parsed, preventing blocking behavior that can slow down page rendering. The Problem with Regular Scripts When a browser encounters a regular tag, it stops HTML parsing, downloads the script, executes it, and then continues parsing. This blocking behavior creates performance bottlenecks and delays page rendering. Regular Script Loading (Blocking) HTML Parsing Script ...
Read MoreConvert set to object - JavaScript?
The task we are going to perform in this article is converting a JavaScript Set to an object. Before we jump into the methods, let's have a quick overview of Sets and objects in JavaScript. A JavaScript Set is a collection of unique values where each value can only appear once. An object in JavaScript is a data structure with properties and values, similar to a dictionary or map. Converting Sets to objects is useful when you need to work with key-value pairs instead of just values. There are several methods to convert a Set to an object ...
Read MoreHow to sort an object in ascending order by the value of a key in JavaScript?
Sorting an object in ascending order by the value of a key is a common task in JavaScript. Objects are data structures, which are a collection of key-value pairs. Since objects in JavaScript are unordered collections, sorting them directly is not possible. This article will guide you on how to sort an object in ascending order by the value of a key in JavaScript. Understanding the Concept Suppose we have the following object: const obj = { "sub1": 56, "sub2": 67, "sub3": 98, "sub4": ...
Read MoreEuclidean Algorithm for calculating GCD in JavaScript
In mathematics, Euclid's algorithm is a method for computing the greatest common divisor (GCD) of two numbers, the largest number that divides both of them without leaving a remainder. The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. For example, 21 is the GCD of 252 and 105 (as 252 = 21 × 12 and 105 = 21 × 5), and the same number 21 is also the GCD of 105 and 252 − 105 ...
Read More