Found 6683 Articles for Javascript

Finding the largest and smallest number in an unsorted array of integers in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 17:42:05

4K+ Views

In the given problem statement we have to find the largest and smallest number in an unsorted array of integers with the help of Javascript functionalities. So we will use an array of integers and find the smallest and largest number from the array. Understanding the Problem The problem we have is to find the largest and smallest values in an unsorted array of integers. So in this task we will see a solution in Javascript. With the help of it we can determine the largest and smallest numbers in an array without sorting the array. For example ... Read More

Factorize a number in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 15:35:11

458 Views

In the given problem statement we are required to factorize the given number with the help of Javascript functionalities. So we will use loops and basic mathematics to factorize the given number. Understanding the Problem The problem at hand is to factorize the given number with the help of Javascript. So the factorization means we will have to find all the prime factors of a number. The prime factors are the prime numbers which can divide the given number without leaving a remainder. So with the help of finding the prime factors we will be able to ... Read More

Pair whose sum exists in the array in JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 12:39:25

185 Views

In this article we will see how to find a pair of items in an array which has sum equals to a specific target number. So we will use JavaScript to implement the algorithm. Understanding the Problem The problem at hand is to find the pair of numbers in the array whose sum is equal to the given target value. And the target value should also be there in the array. Or we can say that we have to identify pairs (a, b) where a + b = c and c is also present in the array. ... Read More

Get the closest number out of an array in JavaScript

AmitDiwan
Updated on 10-Dec-2020 08:00:27

112 Views

We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a single number as the second argument.The function should find and return that number from the array which is closest to the number specified by the second argument.For example −const arr = [34, 67, 31, 53, 89, 12, 4]; const num = 41;Then the output should be 34.ExampleFollowing is the code −const arr = [34, 67, 31, 53, 89, 12, 4]; const num = 41; const findClosest = (arr = [], num) => {    let curr = arr[0];   ... Read More

Check if string ends with desired character in JavaScript

Nikitasha Shrivastava
Updated on 11-Aug-2023 16:30:50

125 Views

In the given problem statement we are required to check if the string ends with the desired character with the help of Javascript functionalities. So we will use basic functions and syntax of Javascript to solve the problem. Understanding the problem The problem at hand is to check if a given string is ending with the given specific character in Javascript. For example suppose we have a string as Hello World! and we have to check if the exclamation ‘!’ mark is present at the end of the string or not. So after comparing with the string the ... Read More

Comparing integers by taking two numbers in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 14:44:55

531 Views

In the given problem statement we have to find the difference between sum of square and square of sum with the help of Javascript functionalities. So we will use basic Javascript to solve this problem. Understanding the Problem The problem at hand is to compare the two integers given. This operation is a common operation when it comes to sorting the data. In this task we will find how to compare two integers and check their relationship with the help of Javascript. For example, we have two integers like 10 and 20. So we can say that 10 ... Read More

Common Character Count in Strings in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 14:03:19

463 Views

In the given problem statement we are required to find the common characters count for the given strings with the help of Javascript functionalities. So we will use basic Javascript to solve this problem. Understanding the problem The problem at hand is to find the common characters between the two given strings. So for solving this problem we will determine how many characters they have in common. For example suppose we have two strings like "abaac" and "baaaa" so in these two strings we can see there are 2 common characters which are 'a' and 'b'. So the ... Read More

Getting century from year in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:04:31

2K+ Views

In the given problem statement we are required to get the century from the given year with the help of Javascript functionalities. So we will use the basic functions of Javascript to solve this problem. Understanding the Problem The problem at hand is to find the century number of the given input year. So basically we have to create an algorithm for finding the century number corresponding to the given year. So first understand what the century number is! A century represents a period of 100 years, beginning from the year 1. For example, the 20th century ... Read More

JavaScript - Find if string is a palindrome (Check for punctuation)

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:29:04

497 Views

In the given problem statement we have to find that the string is a palindrome and the string should also have punctuation and write code with the help of Javascript functionalities. Understanding the problem The problem at hand is to explore how to determine whether a given string is a palindrome or not with the help of Javascript. So let's see what palindrome is first. A palindrome is a word, phrase, a number or a sequence of letters which can be read the same forward and backward. For example: racecar is a palindrome string. Logic ... Read More

Maximum sum of n consecutive elements of array in JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 12:23:07

677 Views

In the given problem statement our aim is to find the maximum sum of n consecutive items of array with the help of Javascript functionalities. So for solving this problem we will use basic Javascript functionalities and produce the maximum sum. Understanding the Problem The problem at hand is to find the maximum sum of n consecutive items in the array. This process will involve identifying a continuous subarray of length n within the given array which has the highest possible sum. For example suppose we have an array as [1, 2, 4, 7, 3, 5] so that ... Read More

Advertisements