• 欢乐的小马驹
    2019-12-28
    通过第二种方式,岂不是时间复杂度更高了?
    
    
  • 九三
    2019-12-15
    老师, 函数式编程和链式编程看的挺像, 有什么区别吗

    作者回复: 函数式编程是和面向对象编程并列的一种编程思想, 链式编程只要写起来是一个链条就可以,面向对象里你可以使用这种链的方式,函数式编程里也可以使用链式。

    所以我觉得两个根本不是一回事,函数式编程是一种编程思想,链式编程是一种书写代码的方式。

    
    
  • pengzishang
    2019-10-15
    let source = "Hello world"
    let target = ["a","e","i","o","u"]

    let firstOrders = target.map { (character) -> Int? in
        let index = source.firstIndex(where: {
            String($0) == character
        })
        
        return index?.utf16Offset(in: source)
    }

    print(zip(target, firstOrders.compactMap({$0 ?? -1})).map({$0}))

    感觉还是不够简明扼要
    展开

    作者回复: let source = "Hello world"
    let target: [Character] = ["a","e","i","o","u"]
    zip(0..<source.count, source).forEach { (index, char) in
        if target.contains(char) {
            print(index)
        }
    }
    因为swift没有yield,所以不是很优雅

    
    
  • pengzishang
    2019-10-15
    if let index = "Hello world".firstIndex(where: {$0 == "e"}){
        print(index.utf16Offset(in: "Hello world"))
    }
    
    
我们在线,来聊聊吧