This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 練習Goroutine | |
| package main | |
| import ( | |
| "math" | |
| "sync" | |
| ) | |
| func sum(id int) { |
-
由於 arguments.callee 是目前的函式,而所有的函式都是物件,你可以因此用 arguments.callee 來在多次呼叫同個函式之間儲存資料。這個函式會記得它被呼叫過多少次:
function counter() { if (!arguments.callee.count) { arguments.callee.count = 0; } return arguments.callee.count++; }
-
使用處理 List 的函數來對字串進行操作。 將兩個 List 合併是很常見的操作,這可以通過 ++ 運算子實現。
-
用 : 運算子往一個 List 前端插入元素會是更好的選擇。
-
: 運算子可以連接一個元素到一個 List 或者字串之中,而 ++ 運算子則是連接兩個 List。若要使用 ++ 運算子連接單個元素到一個 List 之中,就用方括號把它括起使之成為單個元素的 List。
-
可以使用 !! 運算子,取得 List 中的元素(索引的下標為 0)。
-
head返回一個 List 的頭部,也就是 List 的首個元素。
-
求從 10 到 100 中能被 3 或 5 整除數的加總。
sum [x | x <-[10..100], (mod x 3)==0 || (mod x 5)==0]
-
將一個字串倒序,不要使用反轉函數。
let rever' [] =[]; rever' (x:xs) = rever' xs ++ [x] in rever' "Hello World"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var taipei = | |
| { | |
| "中正區": { | |
| "lat": 25.0293008, | |
| "lng": 121.5205833 | |
| }, | |
| "大同區": { | |
| "lat": 25.0645027, | |
| "lng": 121.513314 | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE TemplateHaskell #-} | |
| import Test.QuickCheck | |
| import Test.QuickCheck.All | |
| {- | |
| Problem 01 | |
| Find the last element of a list. |