# Tag: algorithm

## Convert a string with a math formula to an object tree?

I am looking for a function that converts a math string passed as an argument (with the operations +, -, /, *), that returns an object that contains pieces of the math string, in an ordered/better way, which is easier to traverse. Characteristics of the input: is a string containing a formula the formula doesn’t have =, so it isn’t

## Build nodes like array from flat array

I’m trying to restructure the following javascript flat array without parent_id. I want to have a structure for React Tree Table like example in this page: https://www.robinwieruch.de/react-tree-table/ I want a another array that dynamically group according to this array’s keys: I want to have a structure like this and pass an another array to group. Ideally a want sum the

## Pass array in another array of objects

I have this nested array which I am trying to sum the number in the last arrays individually so it should return 400 for each array also trying to get the average of the total, for example if it is 400 then it is 100%, if 399 it will be 99.99%, the average needs to be from 100% and dynamic

## Calculate Percentage of each key in Object

So I have this data, how can I compute their respective percentages? Thank you Answer A simple reference for you by using reduce()

## How can I return the mode that appeared first in an array in Javascript?

I want to create a function that will return the number with highest frequency(mode). For example: if array contains [10, 4, 5, 2, 4] the output should be 4. If there is more than one mode, I want to return the one that appeared in the array first (ie. [10,2,5, 4, 5, 2, 4] should return 2 because it appeared

## Final value returned from a for loop is mysteriously multiplied by 2 – Javascript. How to fix this?

I am coding a cash register…here are the conditions (you can largely ignore these) everything is multiplied by 100 to avoid fractions the value of dif is supposed to be the difference between cash and price * 100 .For now, I am manually assigning its value When I run this function below with the value of dif assigned to 18000

## Better way to reverse a linkedlist in javascript

I tried this: And my Node class: here head is the main LinkedList’s head, and HEAD is the head of new one. I’m using stack here. And the algorithm is in linear complexity. Instead of creating new Node everytime, I think there is some better way to implement this. Can you suggest some other ways? Also is it possible to

## Is there a cleaner way to calculate user session length from such an array?

I have an array of events where every event has an action (login/logout) and a timestamp. I am trying to write a function calculating the total user session length which is defined by the difference between a login and logout. And a login always comes before a logout. This works but I wonder if there is a simpler or cleaner

## Group an object of array based on keys inside of array

Guys this is the most complicated things that i’ve ever met. So, i have an array looks like this. I have an array that consist of Object that also consist of array who had items of name, and value. I wanted to extract the value from the array and merged it with the keys, and then group it into an

## JavaScript – How to calculate the distance from max value in array of objects

I currently have a problems counting the distance between the max value and other values in array. Basically I want to make a new array where the values will be the distances from the max value. What I mean by this: Example I have an array of objects: I want the result of this new algorithm that I am trying