[ Skill ] 扫描 list 中是否含有某元素

https://www.cnblogs.com/yeungchie/

发现有自带函数实现这个功能了 member ,需要计数再用这个新轮子。。

  • code
procedure(ycInListp(scan keylist)
    prog((times)
        times = 0
        foreach(key keylist
            if(scan == key then
                times++
            )
        )
        if(times > 0 then
            return(times)
            else
                return(nil)
        )
    )
)
  • describe
    扫描keylist中是否含有scan并计数,有则返回计数,否则返回nil。

  • example

ycInListp(1 list(1 2 3 2 1 2 1))
=>2
ycInListp(1 list(2 3 2 2))
=>nil
原文地址:https://www.cnblogs.com/yeungchie/p/12830408.html