Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV backend #10

Open
elliotchance opened this issue Jul 11, 2019 · 1 comment
Open

CSV backend #10

elliotchance opened this issue Jul 11, 2019 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@elliotchance
Copy link
Owner

No description provided.

@elliotchance elliotchance added the enhancement New feature or request label Jul 11, 2019
@elliotchance elliotchance added this to the v1.0.0 milestone Jul 11, 2019
@elliotchance
Copy link
Owner Author

people.csv:

First name,Started,Salary
Bob,21 Jun 2007,80000
Jane,4 Apr 2011,105000
Cathy,17 Mar 2019,
John,18 Sep 2018,45000

average-salaries.bento:

Average salary for file path (path is text):
  Declare people-file as csv file
  Declare person as csv record
  Declare total-salaries as a number
  Declare total-people as a number
  Declare salary as a number
  Declare average-salary

  Open csv file path as people-file
  Until people-file has no more records do
    Read next record from people-file into person
    Set salary to person column "Salary"

    # Only include salaries that are known.
    Unless salary is zero do
      Add salary to total-salaries
      Increment total-people
    Done
  done

  Divide total-salaries by total-people into average-salary
  Display average-salary as currency
$ bento average-salaries.bento -- average salary for file "people.csv"
$76666.67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant