Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created November 16, 2018 09:40
Show Gist options
  • Save iporsut/be1eb7dda67535d083c06b60091ec23f to your computer and use it in GitHub Desktop.
Save iporsut/be1eb7dda67535d083c06b60091ec23f to your computer and use it in GitHub Desktop.
Exercise testing

Exercise: Stats

  • ให้สร้างฟังก์ชันที่หาค่าน้อยสุดใน slice ของตัวเลข
  • ให้สร้างฟังก์ชันที่หาค่ามากสุดใน slice ของตัวเลข
  • ให้สร้างฟังก์ชันที่หาค่าเฉลี่ยของตัวเลขที่อยู่ใน slice
  • สร้างฟังก์ชันเดียวที่ได้ค่าทั้งหมดนั้นกลับออกมาเป็น struct
func Min(nums []float64) float64
func Max(nums []float64) float64
func Average(nums []float64) float64
type Report struct {
	Min float64
	Max float64
	Average float64
}
func MakeReport(nums []float64) Report

Exercise: LCD Digit

สร้างฟังก์ชันที่รับตัวเลขจำนวนเต็มแล้วให้แสดงผลลัพธ์ออกมาเป็นตัวเลขที่เป็น grid ขนาด 3x3 ที่ตัวเลข 0 ถึง 9 แทนด้วยรูปร่างต่อไปนี้ (จุดในตัวอย่างนี้คือ space ใส่มาเพื่อให้เห็นว่าแต่ละตำแหน่งใน 3x3 เป็นอะไร)

._.   ...   ._.   ._.   ...   ._.   ._.   ._.   ._.   ._.
|.|   ..|   ._|   ._|   |_|   |_.   |_.   ..|   |_|   |_|
|_|   ..|   |_.   ._|   ..|   ._|   |_|   ..|   |_|   ..|

Example: 910

._. ... ._.
|_| ..| |.|
..| ..| |_|

Exercises: Remove Duplicates

ให้เขียน function ที่รับ slice ของ int แล้วลบข้อมูลที่ซ้ำกันออก

[]string{"a", "b", "a"} => []string{"a","b"}
func RemoveDuplicate(nums []string) []string

Exercises: account package

สร้าง package ที่จัดการ account ของบัญชีออมทรัพย์ โดย package account ต้องมี function

  • func New(name string) *Account // สำหรับสร้าง account ใหม่
  • func Save(account *Account) // สำหรับ save/update account เอาไว้
  • func FindByName(name string) *Account // ค้นหา account ที่เก็บเอาไว้

ส่วน *Account นั้นให้มี Method สำหรับ ฝาก และ ถอน เงิน และเรียกดู Balance ดังนี้

func (a *Account) Withdraw(amount int)
func (a *Account) Deposit(amount int)
func (a *Account) Balance() int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment