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
How to check if an array contains integer values in JavaScript ?
In JavaScript, checking if an array contains integer values requires understanding the difference between numbers and strings that look like numbers. This article explores different approaches to detect actual integer values in arrays. The Problem with String Numbers Arrays often contain string representations of numbers like "123" instead of actual numbers. We need to distinguish between these types. const mixedArray = ["123", 45, "hello", 67.5, "89"]; console.log(typeof "123"); // "string" console.log(typeof 45); // "number" string number Method 1: Using typeof and Number.isInteger() The most ...
Read MoreFunction that returns the minimum and maximum value of an array in JavaScript
Finding the minimum and maximum values in an array is a fundamental task in JavaScript programming. Whether you're analyzing data, implementing algorithms, or building interactive applications, having efficient methods to determine array extremes is essential. Problem Statement Create a JavaScript function that takes an array of numbers as input and returns both the minimum and maximum values. The function should handle arrays of any length efficiently. Sample Input: const inputArray = [5, 2, 9, 1, 7, 4]; Sample Output: const minValue = 1; const maxValue = 9; Using Math.min() and Math.max() ...
Read MoreFinding all peaks and their positions in an array in JavaScript
A peak (local maximum) in an array is an element that is greater than both its neighbors. Finding all peaks and their positions is useful for data analysis, signal processing, and identifying trends. Problem Statement Given an array of integers, we need to find all local maxima (peaks) and return an object containing two arrays: maximas (the peak values) and positions (their indices). Consider this array: const arr = [4, 3, 4, 7, 5, 2, 3, 4, 3, 2, 3, 4]; console.log("Array:", arr); Array: [4, 3, 4, 7, 5, 2, 3, 4, ...
Read MoreAdding Animations on Scroll with HTML, CSS and AOS.js
AOS.js (Animation on Scroll) is a lightweight JavaScript library that makes it easy to add scroll-triggered animations to web pages. By simply adding CSS classes and data attributes to HTML elements, you can create engaging visual effects without writing complex JavaScript code. In this tutorial, we will explore different types of animations available in AOS.js, including fade, flip, and zoom effects, along with practical examples. Setting Up AOS.js Before using AOS.js, you need to include the CSS and JavaScript files in your HTML document. Add the following CDN link in the section: ...
Read MoreHow to center an Image object vertically on current viewport of canvas using FabricJS?
In this tutorial, we are going to show how you can center an Image object vertically on current viewport of canvas using FabricJS. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to center an Image object vertically on current viewport of canvas, we use the viewportCenterV method. Syntax viewportCenterV(): fabric.Object Default Appearance of the Image Object Let's see a code example to see how our ...
Read MoreDifference between Google Script (.GS) and JavaScript (.js)
What is a .GS file? A .GS file contains Google Apps Script code, which is JavaScript-based code designed to automate tasks across Google's suite of applications. These scripts run in Google's cloud environment and can interact with Google Sheets, Docs, Gmail, Drive, and other Google services to create powerful automation workflows. Google Apps Script files are stored on Google's servers and executed in a server-side environment. They enable developers to build web applications, automate repetitive tasks, and integrate Google services with external APIs. Common use cases include sending personalized emails, generating reports from spreadsheet data, and creating custom user ...
Read MoreHow to clone an array in ES6?
In ES6, the spread operator (...) provides the most elegant way to clone arrays. While ES5 used methods like concat() and slice(), ES6 offers a cleaner syntax for array cloning. The Problem with Assignment Operator Using the assignment operator creates a reference, not a copy. This means changes to one array affect the other: Problem with Assignment Operator let output = document.getElementById('output1'); let array1 = ["Hi", "users", "Welcome"]; ...
Read MoreJavaScript: take every nth Element of Array and display a fixed number of values?
In this article, we will learn to extract every nth element from an array and display a fixed number of values in Javascript. The objective is to filter out every second element (or more generally every nth element) from an array and limit the result to a specified count of elements. We will explore different approaches in JavaScript for achieving this functionality, each offering a unique way to solve the problem. Problem Statement Let's say you have an array that takes every nth element. Display a fixed number of values after extracting the elements. Input Let's say the ...
Read MoreProgram to implement Bucket Sort in JavaScript
Bucket Sort is an efficient sorting algorithm that works by distributing elements into multiple buckets based on their values, then sorting each bucket individually. This approach is particularly effective when the input is uniformly distributed across a range. How Bucket Sort Works The algorithm follows these key steps: Find the minimum and maximum values in the array Create a specific number of buckets to hold ranges of values Distribute array elements into appropriate buckets Sort each bucket using a suitable sorting algorithm (like insertion sort) Concatenate all sorted buckets to get the final result ...
Read MoreGet the correct century from 2-digit year date value - JavaScript?
When working with 2-digit year values, you need to determine which century they belong to. A common approach is using a pivot year to decide between 19XX and 20XX centuries. Example Following is the code − const yearRangeValue = 18; const getCorrectCentury = dateValues => { var [date, month, year] = dateValues.split("-"); var originalYear = +year > yearRangeValue ? "19" + year : "20" + year; return new Date(originalYear + "-" + month + "-" + date).toLocaleDateString('en-GB') }; console.log(getCorrectCentury('10-JAN-19')); console.log(getCorrectCentury('10-JAN-17')); console.log(getCorrectCentury('10-JAN-25')); ...
Read More