daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Aug 12th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strings"
  6. )
  7.  
  8. func Check(key string, data []string, op func(k, s string)bool) []string{
  9.         result := make([]string, len(data))
  10.         for i, v := range data {
  11.             if op(key, v){
  12.                 result[i] = v
  13.             }
  14.         }
  15.         return result
  16. }
  17.  
  18. type Persons []string
  19.  
  20. func main() {
  21.     persons := Persons{"Andi", "Beni", "Wuri", "Alan", "Ana"}
  22.     res := Check("an", persons, func(k, s string) bool {
  23.         return strings.Contains(strings.ToLower(s), strings.ToLower(k))
  24.     })
  25.     fmt.Println(res)
  26. }
RAW Paste Data
Top