Algorithm - Baseball game save score - JavaScript

Algorithm - Baseball game save score - JavaScript

Algoritmos

Los Algoritmos son una serie de pasos lĆ³gicos a seguir para resolver un problema, tienen un inicio y un final, datos de entrada, procesos y datos de salida. Son la base para el desarrollo de software.

El proceso se lleva a cabo a travĆ©s de preguntas lĆ³gicas y ciclos repetitivos para realizar cĆ”lculos aritmĆ©ticos y entregar un resultado.

Exercise

You are keeping score for a baseball game with strange rules. The games consists of several rounds, where the scores of past rounds may effect future round's scores.

At the beginning of the game, you start with an empty score. You are given a list of strings ops, where ops[i] is the ith operation you must apply to the record and is one of following:

  • An integer x - Record a new score of x
  • "+" - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.
  • "D" - Record a new score that is double the previous score. It is guaranteed there will always be a previous score
  • "C" - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.

Return the sum of all scores of the record.


Video

SuscrĆ­bete



Try the code in CodePen


See the Pen Basebal score by Vladimir Salguero (@vladisalguero) on CodePen.