存在チェッ ク(Exists,In,Contains)
Python
py
v in items
py
'a' in ['a', 'b', 'c']
Swift
swift
items.contains(v)
条件が満たすものが1個でもあるか
swift
items.contains(where: { $0.hasSuffix("!") })
すべて条件を満たしているか
swift
items.allSatisfy({ $0.hasSuffix("!") })
PHP
php
in_array($v, $items, $strict = true)
php
in_array($v, $items, true)
JavaScript
js
items.includes(v)
js
var arr = ['a', 'b', 'c', 5]
arr.includes('b'); // => true
arr.includes(5); // => true
arr.includes('e'); // => false
Ruby
rb
items.include?(v)
rb
['a', 'b', 'c'].include?('a')
PowerShell
powershell
$items -contains $v
Python 風に、こうでもいい
powershell
$v -in $items
C++
cpp
(find(items.begin(), items.end(), v) != items.end())
cpp
#include <algorithm>
(find(items.begin(), items.end(), v) != items.end())