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

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

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

  • code
procedure(ycInListp(scan keylist)
    prog((count)
        count = 0
        foreach(key keylist
            if(scan == key then
                count++
            )
        )
        if(count > 0 then
            return(count)
        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
posted @ 2020-05-05 13:25  YEUNGCHIE  阅读(835)  评论(0编辑  收藏  举报