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 2 of 17
Implementing counting sort in JavaScript
In the given task, our aim is to create a counting sorting technique and implement this problem with the help of Javascript functionalities. What is Counting Sort? Counting sort is a non-comparison based sorting algorithm that works by counting the occurrences of each distinct element in the input array. It determines the position of each element in the sorted output by calculating how many elements are smaller than it. The algorithm works in several phases: Find the minimum and maximum values in the input array Create a count array to ...
Read MoreFunction to find out palindrome strings JavaScript
In this problem statement, our aim is to create a function to find out that the given string is palindrome with the help of Javascript functionalities. So for solving this problem first we need to understand the problem in simple terms. Understanding the Problem Statement We have given a string as an input string and our main aim is to check if the string is a palindrome string or not. If it is palindrome then return true otherwise return false. What is a Palindrome? A palindrome is a string that reads the same forwards and backwards. ...
Read MoreChecking for string anagrams JavaScript
In this problem statement, our aim is to check for string anagrams with the help of Javascript functionalities. So for solving this problem first we need to understand the problem in simple terms. Understanding the Problem Statement We have given two strings as input and our main aim is to check if the strings are anagrams of each other. If they are anagrams then return true otherwise return false. What are Anagrams? An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all the original letters exactly once. ...
Read MoreReversing the words within keeping their order the same JavaScript
In JavaScript, we can reverse each word in a string while maintaining their original positions. This means "Hello World" becomes "olleH dlroW" - each word is reversed individually, but their order remains unchanged. Understanding the Problem We need a function that takes a string and returns a new string where each word is reversed, but the word positions stay the same. For example: Input: "Hello World" Output: "olleH dlroW" The word order is preserved, but each word's characters are reversed. Method 1: Using Built-in Methods (Recommended) The most efficient approach uses JavaScript's ...
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 MoreSpiraling the elements of a square matrix JavaScript
In this problem statement, our main aim is to spiral the elements of a square matrix with the help of JavaScript functionalities. We'll traverse the matrix in a clockwise direction, starting from the top-left corner and moving in a spiral pattern. Understanding the Problem The problem is to write a function in JavaScript that converts a 2D matrix into a 1D array by traversing elements in a clockwise spiral pattern. For example, if we have a matrix: [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] ...
Read MoreFinding sum of multiples in JavaScript
In JavaScript, finding the sum of multiples of a given number within a specific range is a common programming problem. We need to identify all numbers divisible by the input number and calculate their sum using loops and conditional checks. Understanding the Problem The task is to find the sum of all multiples of a given number within a specified range. A multiple is any number that can be divided evenly by the given number (remainder is zero). For example: if we have number 3 and range 1 to 12, the multiples of 3 are: 3, 6, ...
Read MoreUsing Sieve of Eratosthenes to find primes JavaScript
In this article, we'll implement the Sieve of Eratosthenes algorithm in JavaScript to efficiently find all prime numbers up to a given limit. This classical algorithm is much faster than checking each number individually for primality. What is the Sieve of Eratosthenes Algorithm? The Sieve of Eratosthenes is an ancient and efficient algorithm for finding all prime numbers up to a given range. It works by creating a list of all numbers from 2 to the target number, then systematically eliminating the multiples of each prime number, leaving only the primes. Sieve of ...
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 MoreAbsolute Values Sum Minimization in JavaScript
In JavaScript, finding the value that minimizes the sum of absolute differences from all elements in an array is a fundamental optimization problem. The optimal solution is to find the median of the array. Understanding the Problem Given an array of numbers, we need to find a value x that minimizes the sum of |arr[i] - x| for all elements in the array. Mathematically, this optimal value is always the median of the sorted array. Sum Minimization Concept 1 ...
Read More