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 by Nikitasha Shrivastava
Page 16 of 17
Finding the smallest multiple in JavaScript
In JavaScript, finding the smallest multiple of numbers from 1 to n is equivalent to finding their Least Common Multiple (LCM). This tutorial demonstrates how to solve this problem using loops and mathematical concepts. Understanding the Problem The problem is to find the smallest positive number that is divisible by all numbers from 1 to a given number n. For example, the smallest multiple of numbers 1 to 4 is 12, because 12 is divisible by 1, 2, 3, and 4. Algorithm Logic ...
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 MoreFind the Exact Individual Count of Array of String in Array of Sentences in JavaScript
In JavaScript, you often need to count how many times specific strings appear in an array of sentences. This article demonstrates how to find the exact individual count of each string from a given array within multiple sentences using regular expressions and word boundaries. Understanding the Problem Given an array of strings and an array of sentences, we need to count how many times each string appears across all sentences. The key requirement is to match complete words only, not partial matches within other words. ...
Read MoreManipulating objects in array of objects in JavaScript
In JavaScript, manipulating objects within an array of objects is a common task. JavaScript provides several built-in array methods like map(), filter(), find(), and slice() to efficiently handle these operations. What is Object Manipulation in Arrays? Object manipulation in arrays involves three main operations: Updating - Modifying existing object properties Filtering - Selecting objects based on criteria Adding - Creating new objects or properties JavaScript provides methods like map(), filter(), find(), slice(), sort(), reduce(), and others to perform these manipulations efficiently. Original Array ...
Read MoreMapping an array to a new array with default values in JavaScript
In JavaScript, mapping an array to a new array with default values is a common task when you need to transform data while ensuring missing or invalid values are replaced with fallback values. What is Array Mapping? Array mapping creates a new array by transforming each element of an existing array through a callback function. The original array remains unchanged, and the new array has the same length. const numbers = [1, 2, 3]; const doubled = numbers.map(x => x * 2); console.log(numbers); // Original unchanged console.log(doubled); // New transformed array ...
Read MoreCheck if items in an array are consecutive but WITHOUT SORTING in JavaScript
In JavaScript, checking if array items are consecutive without sorting requires verifying that elements form an unbroken sequence. We can solve this using mathematical properties and built-in array methods. What are Consecutive Items in an Array? Consecutive elements form an unbroken sequence where each number differs by exactly 1 from the next. For example, [1, 2, 3, 4, 5] contains consecutive items in ascending order, while [5, 4, 3, 2, 1] is consecutive in descending order. Example Input/Output Input: [11, 12, 13] Output: true Input: [21, 11, 10] Output: false Method 1: ...
Read MoreGet value for key from nested JSON object in JavaScript
In JavaScript, accessing values from nested JSON objects is a common task when working with APIs and complex data structures. We can retrieve nested values using dot notation, bracket notation, or custom functions. Before exploring different approaches, let's understand what JSON and nested JSON objects are: What is JSON and Nested JSON Objects? JSON (JavaScript Object Notation) is a lightweight, text-based format for representing structured data. It's widely used for data transmission between web applications and servers. Nested JSON objects contain objects within other objects, creating a hierarchical structure. Each nested property has a unique path ...
Read MoreConvert number to characters in JavaScript
In JavaScript, converting numbers to characters is commonly done using ASCII/Unicode values. JavaScript provides the built-in String.fromCharCode() method to convert numeric values to their corresponding characters. The String.fromCharCode() Method The String.fromCharCode() method converts Unicode values to characters. Each number represents a specific character in the ASCII/Unicode table. Syntax String.fromCharCode(num1, num2, ..., numN) Example: Single Number to Character const n = 65; const c = String.fromCharCode(n); console.log(c); console.log("Number 72 becomes:", String.fromCharCode(72)); console.log("Number 101 becomes:", String.fromCharCode(101)); A Number 72 becomes: H Number 101 becomes: e In this ...
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 MoreFinding Lucky Numbers in a Matrix in JavaScript
In the given problem statement we have to write a function to get the lucky numbers in a matrix with the help of Javascript. A lucky number is defined as an element that is the minimum value in its row and the maximum value in its column. Understanding the Problem Statement A lucky number in a matrix must satisfy two conditions: It is the minimum element in its row It is the maximum element in its column For example, in the matrix [[3, 7], [9, 11]], the number 7 ...
Read More