Find the least duplicate items in an array JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

492 Views

We are required to write a JavaScript function that takes in an array of literals which may contain some duplicate values. The function should return an array of all those elements that are repeated for the least number of times. For example− If the input array is − const arr = [1, 1, 2, 2, 3, 3, 3]; Then the output should be − const output = [1, 2]; because 1 and 2 are repeated for the least number of times (2) Example const arr = [1, ... Read More

How to check if an array contains integer values in JavaScript ?

AmitDiwan
Updated on 15-Mar-2026 23:19:00

1K+ Views

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 More

Function that returns the minimum and maximum value of an array in JavaScript

Aayush Mohan Sinha
Updated on 15-Mar-2026 23:19:00

982 Views

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 More

Finding all peaks and their positions in an array in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

702 Views

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 More

Adding Animations on Scroll with HTML, CSS and AOS.js

Mukul Latiyan
Updated on 15-Mar-2026 23:19:00

6K+ Views

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 More

How to center an Image object vertically on current viewport of canvas using FabricJS?

Rahul Gurung
Updated on 15-Mar-2026 23:19:00

361 Views

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 More

Difference between Google Script (.GS) and JavaScript (.js)

Rushi Javiya
Updated on 15-Mar-2026 23:19:00

9K+ Views

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 More

How to clone an array in ES6?

Rushi Javiya
Updated on 15-Mar-2026 23:19:00

742 Views

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 More

JavaScript: take every nth Element of Array and display a fixed number of values?

Alshifa Hasnain
Updated on 15-Mar-2026 23:19:00

1K+ Views

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 More

Program to implement Bucket Sort in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

757 Views

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 More

Advertisements