Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- )
- // map is predefined word in Go. Use apply instead.
- func apply(arr []int, mapper func(int) int) []int {
- out := make([]int, len(arr))
- for i, e := range arr {
- out[i] = mapper(e)
- }
- return out
- }
- // eq declared as before.
- func main() {
- arr := []int{1, 2, 3, 4, 5}
- out := apply(arr, func(n int) int { return n * n })
- if !eq(out, []int{1, 4, 9, 16, 25}) {
- log.Fatal("Wrong value")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement