Javascript Articles

Page 254 of 534

Smallest number that is divisible by first n numbers in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 381 Views

In this problem, we need to find the smallest number that is divisible by all numbers from 1 to n. This is essentially finding the Least Common Multiple (LCM) of the first n natural numbers. Understanding the Problem The problem requires finding the smallest positive integer that is evenly divisible by each of the numbers from 1 to n without any remainder. For example, if n = 4, we need the smallest number divisible by 1, 2, 3, and 4, which is 12. Logic and Approach We solve this using the Least Common Multiple (LCM) concept. ...

Read More

Sort an integer array, keeping first in place in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 338 Views

In JavaScript, when you need to sort an integer array while keeping the first element in its original position, you can combine array slicing with the built-in sort method. This approach preserves the first element while sorting the remaining elements. Understanding the Problem The task is to sort an integer array in ascending order while keeping the first element at index 0. For example, if you have an array [4, 7, 8, 5, 6, 1, 3], the result should be [4, 1, 3, 5, 6, 7, 8] ...

Read More

Sorting according to weights of numbers in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In this problem, we need to sort an array of numbers according to their weights using JavaScript. The weight of a number is defined as the sum of its digits, and we'll create functions to calculate weights and perform the sorting. Understanding the Problem We have to sort numbers according to their weights, where a weight is the sum of a number's digits. For example, if we have an array [19, 11, 12, 15]: Weight of 19 = 1 + ...

Read More

Sorting an integer without using string methods and without using arrays in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 990 Views

In this problem, we need to sort the digits of an integer number without using string methods or arrays in JavaScript. We'll use mathematical operations and loops to extract, compare, and rearrange digits. Understanding the Problem Sorting an integer means arranging its digits in ascending or descending order. For example, if we have the number 784521, the sorted result would be 124578 (ascending) or 875421 (descending). We need to achieve this using only mathematical operations without converting to strings or using arrays. Algorithm Overview Our approach involves two main functions: sortInteger() - Main function ...

Read More

Sum of all prime numbers in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

In JavaScript, calculating the sum of all prime numbers up to a given limit is a common programming challenge. This involves identifying prime numbers and adding them together efficiently. Understanding Prime Numbers A prime number is a positive integer greater than 1 that has no positive divisors other than 1 and itself. For example, if we want to find the sum of all prime numbers up to 10, we identify: 2, 3, 5, 7. Their sum is 2 + 3 + 5 + 7 = 17. ...

Read More

Sum of even Fibonacci terms in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 653 Views

In this article, we'll learn how to calculate the sum of even Fibonacci numbers using JavaScript. The Fibonacci sequence is a series where each number is the sum of the two preceding ones, usually starting with 0 and 1. Understanding the Problem The Fibonacci sequence starts as: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55... Our task is to find all even Fibonacci numbers up to a given limit and calculate their sum. For example, if the limit is 35, the Fibonacci numbers within ...

Read More

Adding binary strings together JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 3K+ Views

The problem is stating that we have to add two binary strings. Binary strings are a sequence of bytes. To add them in JavaScript, we will first convert them to decimal and calculate the sum. After adding those decimal numbers, we will convert it again into binary strings and print the output. What are Binary Strings? Binary numbers or binary strings are sequences of bytes in base 2. It is basically a combination of 0 and 1 to represent any number. Binary addition is one of the fundamental operations in computer science and works similarly to decimal addition, ...

Read More

Counting duplicates and aggregating array of objects in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

Counting duplicates and aggregating arrays of objects is a common task in JavaScript data processing. This involves identifying duplicate elements and creating new structures that group and count related data. Understanding the Problem The goal is to transform an array of objects by grouping similar items and counting occurrences. For example, if we have users with different skills, we want to group by skill and collect all users for each skill. What is Aggregating Array of Objects? Aggregation combines multiple objects into a summarized structure. Instead of having duplicate entries, we group related data together with ...

Read More

Get average of every group of n elements in an array JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In JavaScript, calculating the average of every group of n elements in an array involves dividing the array into chunks and computing the mean for each group. This is useful for data analysis, batch processing, and statistical calculations. Understanding the Problem Given an array of numbers, we need to group consecutive elements into chunks of size n, then calculate the average of each group. For example, with array [1, 2, 3, 4, 5, 6] and group size 2, we get groups [1, 2], [3, 4], [5, 6] with averages [1.5, 3.5, 5.5]. Array Grouping ...

Read More

Grouping data to month wise in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 988 Views

In JavaScript, grouping and sorting data by months is a common requirement when working with date-based information. This involves sorting objects first by year, then by month in chronological order from January to December. Arrays in JavaScript provide powerful methods like sort() and indexOf() that make this task straightforward. The key challenge is properly comparing month names since they need to be sorted in calendar order, not alphabetically. Problem Statement Given an array of objects with year and month properties, we need to sort them chronologically. For example: const data = [ ...

Read More
Showing 2531–2540 of 5,340 articles
« Prev 1 252 253 254 255 256 534 Next »
Advertisements