Skip to content

Reverse polish notation#4

Open
maxnawa31 wants to merge 2 commits intorithmschool:masterfrom
maxnawa31:master
Open

Reverse polish notation#4
maxnawa31 wants to merge 2 commits intorithmschool:masterfrom
maxnawa31:master

Conversation

@maxnawa31
Copy link
Contributor

No description provided.

Copy link
Contributor

@mmmaaatttttt mmmaaatttttt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxnawa31 - thanks for contributing this! minor bookkeeping, mostly around formatting.

In terms of the folder structure, can you rename the folder to problem-solving-evaluate-reverse-polish-notation? I'd generally categorize this as "problem solving" (potentially you could also classify it as a stacks problem, but that's kind of a spoiler for the solution so I'd rather not use the word "stack" in the folder name.)


Write a method called `evalRPN` that evaluates the value of an arithmetic expression in Reverse Polish Notation.

Valid operators are +, -, \*, /. Each operand may be an integer or another expression.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why \* instead of *?


module.exports = {
evalRPN
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add newline

const result = evalRPN(tokens);
expect(result).toEqual(13);
})
}) No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add newline

it("Evaluates correctly for ['2', '1', '+', '3', '*']", () => {
const tokens = ["2", "1", "+", "3", "*"];
const result = evalRPN(tokens);
expect(result).toEqual(9)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't neglect your code formatter! missing semicolon here, also inconsistent use of single vs double quotes etc.

@@ -0,0 +1,43 @@
function evalRPN(tokens) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run this file through prettier too.

if (tokens.length === 1) {
return parseInt(tokens[0]);
}
for (let i = 0; i < tokens.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add line break before for loop


module.exports = {
evalRPN
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add newline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants