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
Alternate addition multiplication in an array - JavaScript
We are required to write a JavaScript function that takes in an array of numbers and returns the alternative multiplicative sum of the elements. For example, if the array is: const arr = [1, 2, 4, 1, 2, 3, 4, 3]; Then the output should be calculated like this: 1*2 + 4*1 + 2*3 + 4*3 2 + 4 + 6 + 12 And the final output should be: 24 How It Works The algorithm pairs consecutive elements starting from index 0. Each pair is multiplied ...
Read MorePrime numbers upto n - JavaScript
Let's say, we are required to write a JavaScript function that takes in a number, say n, and returns an array containing all the prime numbers up to n. For example − If the number n is 24, then the output should be − const output = [2, 3, 5, 7, 11, 13, 17, 19, 23]; Method 1: Basic Prime Check Approach This approach uses a helper function to check if each number is prime: const num = 24; const isPrime = num => { let count ...
Read MoreWhat is a NaN property of a Number object in JavaScript?
In JavaScript, the NaN property is a special value that represents "Not a Number". It is a property of the Number object and can be accessed using Number.NaN. The NaN property is usually produced as a result of an operation that cannot produce a meaningful result. For example, dividing 0 by 0 or trying to parse an invalid number will both produce NaN. Common Operations That Produce NaN console.log(Math.sqrt(-1)); // NaN console.log(0/0); // NaN console.log(parseInt("foo")); // NaN console.log("hello" * 2); ...
Read MoreWith JavaScript Regular Expression find a non-whitespace character.
To find a non-whitespace character in JavaScript regular expressions, use the \S metacharacter. This matches any character that is not a space, tab, newline, or other whitespace character. Syntax \S // Matches any non-whitespace character \S+ // Matches one or more non-whitespace characters \S* // Matches zero or more non-whitespace characters Example: Finding Non-Whitespace Characters JavaScript Regular Expression ...
Read MoreHow to set the color of an elements border with JavaScript?
In this tutorial, we will learn how to set the color of an element's border with JavaScript. The border is the outline of an HTML element. The border can be styled differently with different types of border properties. To set the color of the border of an element with JavaScript, we have the style borderColor property. Using the Style borderColor Property In JavaScript, the style borderColor property of an element is used to set the color of the border of an element. To set the color of the border of an element, we first need to get ...
Read MoreCancels ongoing watchPosition call in HTML5
The clearWatch method cancels an ongoing watchPosition call. When canceled, the watchPosition call stops retrieving updates about the current geographic location of the device. Syntax navigator.geolocation.clearWatch(watchID); Parameters The clearWatch method takes one parameter: watchID: The ID returned by watchPosition() that identifies the watch operation to cancel Example: Watch and Stop Location Updates var watchID; ...
Read MoreUsage of font-family property in CSS
The font-family property in CSS specifies the typeface or font family to be used for displaying text. It accepts a prioritized list of font names, allowing fallback options if the preferred font is not available on the user's system. Syntax font-family: "font-name", fallback1, fallback2, generic-family; Font Family Categories CSS defines five generic font families: serif - Fonts with decorative strokes (Times, Georgia) sans-serif - Clean fonts without strokes (Arial, Helvetica) monospace - Fixed-width fonts (Courier, Monaco) cursive - Script-like fonts (Comic Sans, Brush Script) fantasy - Decorative display fonts (Impact, Papyrus) ...
Read MoreFind n highest values in an object JavaScript
Let's say, we have an object that describes various qualities of a football player like this − const qualities = { defence: 82, attack: 92, heading: 91, pace: 96, dribbling: 88, tenacity: 97, vision: 91, passing: 95, shooting: 90 }; We wish to write a function that takes in such object and a number n (n ≤ no. of keys ...
Read MoreHow to create an image of matrix of pixels in R?
A matrix can be converted into a pixel's image representation in R. This visualization technique displays matrix values as colored pixels, where each matrix element corresponds to a pixel with intensity or color based on its value. We can create pixel matrix images using R's image() function with the useRaster argument for optimized rendering. Syntax image(x, y, z, zlim, xlim, ylim, col, add, xaxs, yaxs, xlab, ylab, breaks, oldstyle, useRaster, ...) Basic Matrix Image Creation Let's start with a simple 10x10 matrix of random values: M
Read MoreJavaScript RegExp return values between various square brackets? How to get value brackets?
Extracting values between various square brackets can be done using JavaScript regular expressions. The regular expressions in JavaScript are useful for extracting values enclosed within different types of brackets, such as square brackets ([ ]), curly brackets ({ }), and parentheses "( )". In this article, we'll look at how to use JavaScript's RegExp to find and get content that is inside square brackets easily. Understanding JavaScript RegExp Regular expressions (RegExp) are patterns used to match and manipulate strings in JavaScript. JavaScript RegExp helps you find and get text that is inside specific brackets by using patterns. ...
Read More