This language bar is your friend. Select your favorite languages!

Idiom #191 Check if any value in a list is larger than a limit

Given a one-dimensional array a, check if any value is larger than x, and execute the procedure f if that is the case

if(a.some(item => item > x)){
	f()
}
using System.Linq;
if (a.Any(e => e > x))
    f();
if (any(a > x)) call f
for _, v := range a {
	if v > x {
		f()
		break
	}
}
if (count(array_filter($a, function($v) { return $v > $x; })))
  f();

// or with intermediate steps
$tmp = array_filter(
  $a,
  function ($v) { return $v > $x; }
)
if (count($tmp))
  f();

// or with array reduce instead
if (
  array_reduce($a, 
    function($old, $item) { return $old or ($item > $x); }
  )
)
  f();

// Array reduce takes the old result $old, and 
// applies $item (from $a) to the old result 
// iteratively. We use the 'or' boolean operator
// to implement an 'any' operation.
for v in a do if v > x then f;
use List::Util qw(any);
f if any { $_ > $x } @a;
if any(v > x for v in a):
    f()
f if a.any?{|v| v > x }
if a.iter().any(|&elem| elem > x) {
    f()
}

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

tkoenig