Menu
Coddy logo textTech

Budget Planner

Part of the Logic & Flow section of Coddy's R journey. Lesson 63 of 64.

challenge icon

Challenge

Hard

Complete budget(lines). The first line is the header month,type,amount and every other line is one entry, such as 2024-01,income,3000. An entry is valid when its type is income or expense and its amount is a number above 0; skip every other entry.

Return one line per month in the valid entries, in order, 2024-01: income 3000.00, spent 1250.50, saved 1749.50, where saved is income minus spending (a month without income or spending counts 0 for it). Then add Best month: with the month that saved the most (the first one when several tie) and Skipped: with the number of skipped entries.

When no entry is valid, return only No valid entries and the Skipped line.

The supplied code passes every input line to budget() and prints each returned line.

Try it yourself

budget <- function(lines) {
  # Write your code here
  character(0)
}

# Supplied input/output code: keep it as it is
input <- suppressWarnings(readLines(file("stdin")))
cat(budget(input), sep = "\n")

All lessons in Logic & Flow

Practice on your own: Online R compiler