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
Web Development Articles
Page 313 of 801
Retrieve key and values from object in an array JavaScript
In JavaScript, extracting keys and values from objects within an array is a common task when processing data structures. This can be accomplished using built-in Object methods like Object.keys() and Object.values(). Understanding the Problem When working with arrays of objects, you often need to access both the property names (keys) and their corresponding values. JavaScript objects are collections of key-value pairs, and the Object class provides methods to extract this information efficiently. Using Object.keys() and Object.values() The Object.keys() method returns an array of property names, while Object.values() returns an array of property values from an object. ...
Read MoreShift strings Circular left and right in JavaScript
The main objective for the problem statement is to perform a circular shift on the strings in Javascript. The circular shifts can be left shift or right shift. And implement this solution in Javascript. Understanding the Problem The problem at hand is to shift the strings circularly left and right with the help of Javascript functionalities. Circular shifting means we have to move the characters of the given string in a circular manner in which the characters that are to be shifted beyond the boundaries of the string should reappear at the opposite end. Logic for the ...
Read MoreShortest distance between objects in JavaScript
In JavaScript, calculating the shortest distance between two objects requires their coordinates and the Euclidean distance formula. This is commonly used in game development, mapping applications, and geometric calculations. Understanding the Problem To find the shortest distance between two objects, we need their position coordinates (x, y). The distance is calculated using the Euclidean distance formula: √[(x₂-x₁)² + (y₂-y₁)²] The Distance Formula The Euclidean distance formula calculates the straight-line distance between two points in a coordinate system: ...
Read MoreSmallest number that is divisible by first n numbers in JavaScript
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 MoreSort an integer array, keeping first in place in JavaScript
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 MoreSorting according to weights of numbers in JavaScript
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 MoreSorting 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 More