refactor: file append exercises

This commit is contained in:
Inanc Gumus
2019-03-06 19:41:06 +03:00
parent 0a044c6120
commit 51b5bc21fe
3 changed files with 19 additions and 11 deletions

View File

@ -1,7 +1,7 @@
package main
// ---------------------------------------------------------
// EXERCISE: Sort to a file
// EXERCISE: Sort and write items to a file
//
// 1. Get arguments from command-line
//
@ -25,17 +25,18 @@ package main
//
// HINTS
//
// ONLY READ THIS IF YOU GET STUCK
// + REMEMBER: os.Args is a []string
//
// Below, []string means string slice, []byte means byte slice.
// + String slices are sortable using `sort.Strings`
//
// + You can use the os.Args[1:] to get a []string
// + Then you can sort it using sort.Strings
// + Use ioutil.WriteFile to write to a file.
//
// + But you need to convert []string to []byte to be able to
// write it to a file using the ioutil.WriteFile.
//
// + To do that, create a new []byte and append the elements of your
// []string.
//
// ---------------------------------------------------------
func main() {

View File

@ -8,9 +8,9 @@ import (
)
// ---------------------------------------------------------
// EXERCISE: Sort to a file with ordinals
// EXERCISE: Sort and write items to a file with their ordinals
//
// Use the previous exercise: Append #4
// Use the previous exercise.
//
// This time, print the sorted items with ordinals
// (see the expected output)
@ -35,10 +35,10 @@ import (
//
// + You can use strconv.AppendInt function to append an int
// to a byte slice. strconv contains a lot of functions for appending
// other basic types as well.
// other basic types to []byte slices as well.
//
// + You can append individual characters to a byte slice using
// rune literals:
// rune literals (because: rune literal are typeless numerics):
//
// var slice []byte
// slice = append(slice, 'h', 'i', ' ', '!')

View File

@ -1,7 +1,7 @@
package main
// ---------------------------------------------------------
// EXERCISE: Print the directories
// EXERCISE: Find and write the names of subdirectories to a file
//
// Create a program that can get multiple directory paths from
// the command-line, and prints only their subdirectories into a
@ -43,7 +43,14 @@ package main
// (A directory is also a file)
//
// + You can use IsDir method of a FileInfo value to detect
// whether a file is a directory or not: go doc os.FileInfo.IsDir
// whether a file is a directory or not.
//
// Check out its documentation:
//
// go doc os.FileInfo.IsDir
//
// # or using godocc
// godocc os.FileInfo.IsDir
//
// + You can use '\t' escape sequence for indenting the subdirs.
//