看到这样的代码,更加喜欢 Go

package main

import (
    "fmt"
    "strings"
)

func stripchars(str, chr string) string {
    return strings.Map(func(r rune) rune {
        if strings.IndexRune(chr, r) < 0 {
            return r
        }
        return -1
    }, str)
}

func main() {
    fmt.Println(stripchars("She was a soul stripper. She took my heart!",
        "aei"))
}

共 3 个回复


webboy

return 后面还能加程序段啊

# 0

lzy7199

可以呀,只要返回值是string就可以了

# 1

shaun

closure 都这样吧

# 2