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
Search from an array of objects via array of string to get array of objects in JavaScript
Filtering an array of objects based on keys from another array is a common requirement in JavaScript. This tutorial shows how to extract matching objects using various approaches. Problem Statement Given an array of strings and an array of objects, we need to filter objects whose KEY property exists in the string array: const searchKeys = ['1956888670', '2109171907', '298845084']; const users = [ { KEY: '1262875245', VALUE: 'Vijay Kumar Verma' }, { KEY: '1956888670', VALUE: 'Sivakesava Nallam' }, { KEY: '2109171907', VALUE: 'udm analyst' ...
Read MoreComputing the Cartesian Product of Two Sets in JavaScript
In set theory, a Cartesian product is a mathematical operation that returns a set from multiple sets. For sets A and B, the Cartesian product A × B is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B. We need to write a JavaScript function that takes two arrays representing distinct sets and returns a 2-D array containing their Cartesian product. What is Cartesian Product? The Cartesian product creates all possible combinations between elements of two sets. If set A has m elements and set B has n elements, the ...
Read MoreSorting string of words based on the number present in each word using JavaScript
We are required to write a JavaScript function that takes in a string that represents a sentence. Our function should sort this sentence. Each word in the sentence string contains an integer. Our function should sort the string such that the word that contains the smallest integer is placed first and then in the increasing order. Problem Statement Given a string containing words with embedded numbers, we need to sort the words based on the numerical values they contain. For example, "is2 Thi1s T4est 3a" should become "Thi1s is2 3a T4est" because the numbers are in order ...
Read Morecrypto.getCurves() Method in Node.js
The crypto.getCurves() method returns an array containing names of all supported elliptic curves in Node.js. These curves are used for creating Elliptic Curve Diffie-Hellman (ECDH) key exchange objects for secure cryptographic operations. Syntax crypto.getCurves() Parameters This method takes no parameters since it returns a complete list of all available elliptic curves. Return Value Returns an array of strings, where each string represents the name of a supported elliptic curve. Example Here's how to use crypto.getCurves() to retrieve all available elliptic curves: // Importing the crypto module const crypto ...
Read MoreExplain ReactNative SwitchSelector Component
SwitchSelector is a React Native component that functions like a radio toggle button, allowing users to select from multiple options (more than 2). It's particularly useful for creating segmented controls and option selectors in mobile applications. Installation To work with SwitchSelector, you need to install the package: npm i react-native-switch-selector --save-dev Basic Syntax The basic SwitchSelector structure looks as follows: console.log(`value selected is : ${value}`)} /> Properties Here are the important properties of SwitchSelector: ...
Read MoreHow to Detect if CAPS Lock is ON using JavaScript?
In this article, we are going to explore the CAPS LOCK key and how to check if it is turned on or not using JavaScript on a webpage. While working with modern web applications, we often require information about user interaction and experience. The user interacts with a website to execute functionality like hitting an API, handling clicks or buttons that trigger methods, and many more. In some cases, we might need to know whether the CAPS LOCK key is turned on or not. One use case can be any authentication system that notifies the user that the ...
Read MoreHow to test if a URL string is absolute or relative - JavaScript?
Knowing whether a URL string is absolute or relative allows you to make decisions about content loading and routing in your JavaScript applications. In this article, we'll explore different methods to determine if a given URL string is absolute or relative. Understanding URL Types Absolute URL contains all necessary information to locate a resource, including the protocol (http/https) and domain name. Syntax https://www.tutorialspoint.com/index.htm Relative URL contains only the path information and relies on the current page's context to resolve the full location. Syntax /index.htm ../images/logo.png index.htm Method 1: ...
Read MoreChecking for straight lines in JavaScript
We need to write a JavaScript function that takes an array of coordinate pairs and determines if all points form a straight line. Each subarray contains exactly two items representing x and y coordinates. Our function checks whether the coordinates form a straight line by calculating and comparing slopes between points. For example: [[4, 5], [5, 6]] should return true (slope = 1) [[1, 2], [2, 3], [4, 5]] should return true (all have slope = 1) [[1, 1], [2, 2], [3, 4]] should return false (different slopes) The array is guaranteed to contain ...
Read MoreConvert array with duplicate values to object with number of repeated occurrences in JavaScript
When working with arrays that contain duplicate values, you often need to count occurrences and convert them into a structured format. This article shows how to transform an array with duplicates into an array of objects containing each unique value and its count. Problem Statement Suppose we have an array with duplicate entries like this: const arr = ['California', 'Texas', 'Texas', 'Texas', 'New York', 'Missouri', 'New Mexico', 'California']; console.log("Original array:", arr); Original array: [ 'California', 'Texas', 'Texas', 'Texas', 'New York', ...
Read MoreDisplaying likes on a post wherein array specifies the names of people that liked a particular post using JavaScript
We need to write a JavaScript function that takes an array of names representing people who liked a post. The function should format the output based on the number of likes: show all names for 3 or fewer likes, or show the first two names plus the remaining count for more than 3 likes. Problem Statement Create a function that displays likes in a user-friendly format: 0 likes: "no one likes this" 1 like: "John likes this" 2 likes: "John and Mary like this" 3 likes: "John, Mary and Bob like this" 4+ likes: "John, Mary and ...
Read More