Found 9321 Articles for Object Oriented Programming

JavaScript program to convert positive integers to roman numbers

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:30:42

416 Views

In the given problem we have to change the given positive number (the number should be an integer number) into the corresponding roman number and then implement the code using Javascript. Understanding the problem We have to write a Javascript program to generate the roman number representation of given integer numbers in the given problem statement. The code should accept a positive integer as input and will be able to transform the integer into its equivalent roman number. For example: suppose we have an integer number 5 so here 5 is the input integer number and the ... Read More

How to reverse a string using only one variable in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:19:30

150 Views

In this problem statement, our target is to print the reverse string using only one variable and implement the solution with the help of Javascript. So we can solve this problem with the help of loops in Javascript. Understanding the problem The given problem is stating that we have given a string to which we have to reverse the string. In simple terms we can say that if we have the string “Hello World”, the reverse of this string will be “dlroW ,olleH”. Logic for the given problem In order to reverse the given ... Read More

Shortest distance between objects in JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 16:50:13

390 Views

In this problem we have to calculate and find the shortest distance between two given objects in Javascript. So we will write a function to do this operation and also we will see its time and space complexity. We must consider the positions and coordinates of the objects in some way. Understanding the Problem The problem says to find the shortest path between the two given objects. So we will use two coordinates. And define a function which will have four parameters. These parameters will represent the x and y coordinates of the two objects. Inside the function ... Read More

Group a sorted array based on the difference between current and previous elements in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:10:05

353 Views

In the given problem statement we have to group a sorted array based on the difference between the current and previous elements with the help of Javascript functionalities. To group a sorted array based on the difference between the current and previous items we can iterate over the array and create a new array of groups. Understanding the Problem Statement The above problem statement states that we have to find out the group of elements based on the difference between the current and previous elements in the array. As we have given a sorted array so we need ... Read More

Highest and lowest value difference of array JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:14:24

403 Views

In this problem we have to create an algorithm to get the highest and lowest value difference of an array with the help of Javascript functionality. So we will solve the problem with for loop and initialization of highest and lowest values to Infinity. Understanding the logic of the problem statement The problem statement is asking to write the code for getting the highest and lowest value difference of the array. So for solving this task we will initialize two variables, these variables will store the highest and lowest values. And then iterate through every element ... Read More

JavaScript Sum odd indexed and even indexed elements separately and return their absolute difference

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:32:35

1K+ Views

In this problem we will understand how to get the absolute difference of the sum of odd indexed and even indexed items separately with the help of Javascript functionalities. We will use a simple loop to iterate through all the elements of the array. Understanding the problem statement To understand the above problem statement we will break down the problem step by step: So we are given an array of numbers. Our task is to separate the items in the array in two groups: first ... Read More

Average with the Reduce Method in JavaScript

AmitDiwan
Updated on 11-Aug-2023 16:14:19

723 Views

In the given problem statement, our aim is to get the average of all the items with the help of the reduce method of Javascript. So for doing this task we will create a function and give an array as a parameter. Understanding the problem statement We have given a task to calculate the average value of the given items in the array. And we have to use the reduce method which is a predefined method of Javascript. For example if we have an array as [1, 2, 3, 4, 5], so the average value of the ... Read More

Remove duplicate items from an array with a custom function in JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 16:30:24

320 Views

In this problem statement our aim is to write an algorithm to remove duplicate items from an array with a function with the help of Javascript functionalities. Understanding the problem statement In the above problem statement we have to create a function by which we can accept an array as a parameter and give a new array to store the unique items from the given input array and without including the identical values. For example - suppose we have an array as [0, 0, 2, 2, 3, 3] so after removing the duplicate numbers we will have ... Read More

Convert string with separator to array of objects in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 15:22:37

240 Views

In this article we will discuss algorithm and complexity for converting string with separator to array of objects with the help of Javascript functionalities. For doing this task we will use split and map functions of Javascript. Understanding the problem statement The problem statement says to write a function which can convert a given string with the given separator into an array of objects in Javascript. For example, if we have a string "name1, name2, name3" and a separator ", " then we have to convert these strings into an array of objects which looks like: [{value: ... Read More

Get all substrings of a string in JavaScript recursively

Nikitasha Shrivastava
Updated on 18-May-2023 13:53:48

2K+ Views

In the provided problem statement, our aim is to get all substrings of a string recursively with the help of Javascript. So here we will be creating a recursive function that can generate all possible substrings of a given input string. Understanding the problem statement The problem statement is asking us to create a recursive function which can generate all the possible substrings of a given input string with the help of Javascript. A substring is any continuous sequence of characters within the input string. For example: input strings “xy" so the possible substrings are "x", "y", and "xy". Algorithm ... Read More

Advertisements