下記length'
, all'
をfoldl
, foldr
, foldl1
, foldr1
のいずれかを用いて実装せよ。
length'
, all'
の挙動はlength
, all
を参照すること。
length' :: [a] -> Int
all' :: (a -> Bool) -> [a] -> Bool
import System.Random | |
dice :: StdGen -> Int | |
dice gen = num | |
where (num, _) = diceWithRandomGen gen | |
diceWithRandomGen :: StdGen -> (Int, StdGen) | |
diceWithRandomGen = randomR (1, 6) | |
threeTimesDiceRoll :: StdGen -> (Int, Int, Int) |
length' :: String -> Int | |
length' = foldl (\ x _ -> x + 1) 0 | |
last' :: Show a => [a] -> (Maybe a) | |
last' = foldl (\ _ x -> Just x) Nothing | |
head' :: Show a => [a] -> (Maybe a) | |
head' [] = Nothing | |
head' (x:_) = Just x |
下記がインストール済み
nvmのインストールの仕方くらいは自分で調べてね☆
_.mixin({ | |
sum: function(list, callback) { | |
return _.reduce(list, function(memo, item) { | |
return memo + callback(item); | |
}, 0); | |
} | |
}); | |
// == test == | |
// _.sum([{price:10}, {price:20}, {price:30}], function(item) { return item.price; }); |