Found 9326 Articles for Object Oriented Programming

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

123 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

514 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

451 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

486 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

654 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

How to shift each letter in the given string N places down in the alphabet in JavaScript?

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

1K+ Views

In the given problem statement our aim is to shift every letter in the given string N places down in the alphabet with the help of Javascript functionalities. So we will use some basic Javascript methods to complete the given task. Understanding the Problem The problem at hand is to shift the character of the given string up to the N places down in the alphabets with the help of Javascript. The purpose of this problem is we need to take a string as input and we have to update the given string by shifting every letter N ... Read More

How to get almost increasing sequence of integers in JavaScript ?

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:16:56

303 Views

In the given problem statement we have to get an almost increasing sequence of integers with the help of Javascript functionalities. So we will use some basic functionalities of mathematics and Javascript. Understanding the problem The problem at hand is to generate an almost increasing series of integers in Javascript. So the almost increasing sequence is a sequence in which every item is greater than or equal to the previous item. In other terms we will say it allows for a single item in the sequence where an item is smaller than the previous item. So the resultant ... Read More

Finding the nth prime number in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 17:48:50

4K+ Views

In the given problem statement our task is to find the nth prime number with the help of Javascript functionalities. So we will use two functions to solve this problem. Understanding the Problem The problem at hand is to find the nth prime number using the Javascript programming. So the prime number is a positive integer number which is greater than 1 and which has no positive divisors other than 1 and the number itself. The task is to create a Javascript function which takes an input n. Here n represents the position of the prime number which ... Read More

Advertisements