fix: slicing-housing-prices exercise bug

This commit is contained in:
Inanc Gumus
2019-01-30 17:01:50 +03:00
parent 8ec394bc10
commit d88da48bc6
2 changed files with 21 additions and 1 deletions

View File

@ -94,6 +94,21 @@ package main
// Istanbul 500 10 5 1000000
//
//
// Note : It works even if the Price's index > Size's index
//
// In that case, it resets the invalid starting position to 0.
//
// But it still uses the Size column.
//
// go run main.go Price Size
// Location Size
//
// New York 100
// New York 150
// Paris 200
// Istanbul 500
//
//
// HINTS
//
// + strings.Split function can separate a string into a []string

View File

@ -45,10 +45,15 @@ Istanbul,500,10,5,1000000`
}
}
// from cannot be greater than to: reset invalid arg to 0
if from > to {
from = 0
}
for i, row := range rows {
cols := strings.Split(row, separator)
// print the only the requested columns
// print only the requested columns
for _, h := range cols[from:to] {
fmt.Printf("%-15s", h)
}