Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- average :: [Int] -> Int
- average xs = sum xs `div` length xs
- average' :: [Int] -> Int
- average' xs = foldr (+) 0 xs `div` length xs
- splaszcz :: [[a]] -> [a]
- splaszcz xss = foldl (++) [] xss
- multiplyLengthLambda :: [Int] -> [Int]
- multiplyLengthLambda xs = map (\x -> x * length xs) xs
- multiplyLengthPartial :: [Int] -> [Int]
- multiplyLengthPartial xs = map (* length xs) xs
- =-=-=-=
- factorial :: Int -> Int
- factorial n
- | n < 0 = -1
- | n == 0 = 1
- | otherwise = n * factorial (n - 1)
- factorial :: Int -> Int
- factorial n = case n of
- _ | n < 0 -> -1
- | n == 0 -> 1
- | otherwise -> n * factorial (n - 1)
- =-=-=-=
- findLastIndex :: Eq a => a -> [a] -> Int
- findLastIndex target xs = findLastIndexHelper target xs (-1) 0
- where
- findLastIndexHelper _ [] lastIndex _ = lastIndex
- findLastIndexHelper target (x:xs) lastIndex currentIndex =
- if x == target
- then findLastIndexHelper target xs currentIndex (currentIndex + 1)
- else findLastIndexHelper target xs lastIndex (currentIndex + 1)
- findFirstIndex :: Eq a => a -> [a] -> Int
- findFirstIndex target xs = findFirstIndexHelper target xs (-1) 0
- where
- findFirstIndexHelper _ [] lastIndex _ = lastIndex
- findFirstIndexHelper target (x:xs) lastIndex currentIndex
- | x == target = findFirstIndexHelper target xs currentIndex (currentIndex + 1)
- | otherwise = findFirstIndexHelper target xs lastIndex (currentIndex + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement