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
Even index sum in JavaScript
We need to write a JavaScript function that calculates the sum of all integers at even indices (0, 2, 4, etc.) in an array, then multiplies this sum by the last element of the array. Problem Statement Given an array of integers, find the sum of elements at even indices and multiply by the last element. Input: [4, 1, 6, 8, 3, 9] Even indices: 0, 2, 4 → elements: 4, 6, 3 Sum: 4 + 6 + 3 = 13 Last element: 9 Result: 13 × 9 = 117 Solution const ...
Read MoreFinding the length of longest vowel substring in a string using JavaScript
Problem We are required to write a JavaScript function that takes in a string. Our function should return the length of the longest contiguous substring that contains only vowels. Approach The solution uses a sliding window approach to track consecutive vowels. We maintain two variables: cur for the current vowel sequence length and max for the longest sequence found so far. Example Following is the code − const str = 'schooeal'; const findLongestVowel = (str = '') => { let cur = 0; let max ...
Read Morecrypto.createDiffieHellmanGroup() Method in Node.js
The crypto.createDiffieHellmanGroup() method creates a predefined Diffie-Hellman group using well-known parameters. This is an alias for crypto.getDiffieHellman() and provides a secure way to establish shared secrets between parties. Syntax crypto.createDiffieHellmanGroup(name) Parameters name − A string specifying the predefined group name (e.g., 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16', 'modp17', 'modp18'). Return Value Returns a DiffieHellman object that can generate keys and compute shared secrets. Example 1: Basic Usage with modp1 Create a file with name − diffieHellmanGroup.js and copy the below code snippet. After creating ...
Read MoreHow to show ProgressBar in ReactNative?
ProgressBar is a way to tell users that the content will be available in sometime. It can best be used when you submit something to the server and wait for the server to respond. To work with the progress bar component install react-native-paper module using npm. The command to install react-native-paper is − npm install --save-dev react-native-paper Basic Syntax The basic component of progress bar is as follows− To work with Progress Bar you need to import it from react-native-paper as follows − import { ProgressBar} ...
Read MoreHow to set the width of stroke of Rectangle using FabricJS?
In this tutorial, we are going to learn how to set the width of stroke of a Rectangle using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. The strokeWidth property allows us to specify the width of a stroke for an object in pixels. Syntax new fabric.Rect({ strokeWidth: Number }); Parameters ...
Read MoreWhat are Architecture Flux Components in JavaScript?
Flux is a JavaScript application architecture pattern developed by Facebook for building scalable web applications. Originally designed for React applications, Flux provides a unidirectional data flow pattern that makes application state more predictable and easier to debug. The Flux architecture consists of four main components that work together to manage data flow in a predictable way. Core Flux Components Flux architecture is built around four key components that ensure unidirectional data flow: Actions − Plain JavaScript objects that describe what happened in the application Dispatcher − Central ...
Read MoreValidate Tutorialspoint URL via JavaScript regex?
To validate a TutorialsPoint URL using JavaScript, you can use regular expressions to check if the URL matches the expected domain pattern and extract specific parts of the URL. Regular Expression Pattern The regex pattern /^https?:\/\/(tutorialspoint\.com)\/(.*)$/ breaks down as follows: ^ - Start of string https? - Matches "http" or "https" :\/\/ - Matches "://" (tutorialspoint\.com) - Captures the domain (escaped dot) \/ - Matches forward slash (.*)$ - Captures everything after the domain until end of string Example function validateTutorialspointURL(myURL) { var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/; ...
Read MoreExtract arrays separately from array of Objects in JavaScript
Suppose, we have an array of objects like this − const arr = [{ name : 'Client 1', total: 900, value: 12000 }, { name : 'Client 2', total: 10, value: 800 }, { name : 'Client 3', total: 5, value : 0 }]; We are required to write a JavaScript function that takes in one such array and extracts a separate array for each object property. Therefore, ...
Read MoreConvert number to characters in JavaScript
In JavaScript, converting numbers to characters is commonly done using ASCII/Unicode values. JavaScript provides the built-in String.fromCharCode() method to convert numeric values to their corresponding characters. The String.fromCharCode() Method The String.fromCharCode() method converts Unicode values to characters. Each number represents a specific character in the ASCII/Unicode table. Syntax String.fromCharCode(num1, num2, ..., numN) Example: Single Number to Character const n = 65; const c = String.fromCharCode(n); console.log(c); console.log("Number 72 becomes:", String.fromCharCode(72)); console.log("Number 101 becomes:", String.fromCharCode(101)); A Number 72 becomes: H Number 101 becomes: e In this ...
Read MorePrimality test of numbers in JavaScript
A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. All other natural numbers greater than 1 are called composite numbers. A primality test is an algorithm for determining whether an input number is prime. We are required to write a JavaScript function that takes in a number and checks whether it is a prime or not. Basic Primality Test Algorithm The most efficient approach is to check divisibility up to the square root of the number, skipping even numbers after checking for 2. ...
Read More