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
Object Oriented Programming Articles
Page 63 of 589
Sorting an integer without using string methods and without using arrays in JavaScript
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 MoreSum of all prime numbers in JavaScript
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 MoreSum of even Fibonacci terms in JavaScript
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 MoreAdding binary strings together JavaScript
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 MoreCounting duplicates and aggregating array of objects in JavaScript
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 MoreGet average of every group of n elements in an array JavaScript
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 MoreGrouping data to month wise in JavaScript
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 MoreHow to get single array from multiple arrays in JavaScript
In this article, we will explore how to combine multiple arrays into a single array in JavaScript. This is a common task when working with data manipulation and array operations. We will cover three effective methods: the spread operator (ES6), the concat() method, and using push() with the spread operator. Each approach has its own advantages and use cases. Understanding the Problem When working with multiple arrays, you often need to merge them into one continuous array while maintaining the original order of elements. Input Arrays: ...
Read MoreHow to sort an array of objects based on the length of a nested array in JavaScript
In JavaScript, you can sort an array of objects based on the length of nested arrays using the sort() method with a custom comparison function. This technique is useful when organizing data by array size. Understanding the Problem Consider an array of objects where each object contains a nested array property. To sort by nested array length, we need a comparison function that compares the length property of these nested arrays. Sorting by Nested Array Length Before Sorting ...
Read MoreMerge and group object properties in JavaScript
In JavaScript, merging and grouping object properties is a common task when working with arrays of objects. This technique allows you to combine objects that share a common property (like a name or ID) into single objects with all their properties merged. Understanding the Problem We need to create a JavaScript function that takes an array of objects and groups them by a common property (like 'name'), merging all properties of objects that share the same value for that property. Input: [ {name: 'Adi', age: 22, color:'Black'}, {name: 'Adi', weight: 40, height: ...
Read More