Your boss has asked you to add up a sequence of positive numbers to determine how much money your company made last year. Unfortunately, your boss reads out numbers incorrectly from time to time.
Fortunately, your boss realizes when an incorrect number is read and says “zero”, meaning “ignore the current last number.” Unfortunately, your boss can make repeated mistakes, and says “zero” for each mistake.
For example, your boss may say “One, three, five, four, zero, zero, seven, zero, zero, six”, which means the total is 7 as explained in the following chart:
At any point, your boss will have said at least as many positive numbers as “zero” statements. If all positive numbers have been ignored, the sum is zero.
File Specification
Create the executable file ~/js/zero.js that reads the sequence of boss statements and computes the correct sum.
The top of the file must be a block comment with your name.
Optionally include the date and a brief description of the program.
/**
* Author: Mr. Squirrel
* Date: Feb. 2025
* Description: Zero That Out (Sr. CCC 2015)
**/
The first line of code must be:
'use strict';
Input Specification:
The command-line will contain a non-empty list of positive integers, or zero, which are the values your boss will “say”.
Example: ./zero.js 18 3 5 24 0 0 17 0 0 6
Output Specification:
The output is one line, containing the integer which is the correct sum of the integers read, taking the “zero” statements into consideration.
Examples:
./zero.js 3 0 4 0 5 4 5 0 0 1 0 0 9 0
0
./zero.js 8 1 0 9 0 7 4 0 0 1
9