Logo

Programming-Idioms

  • Go
  • Clojure
  • Python

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 any(v > x for v in a):
    f()
if any(z > x for z in a): f()
for _, v := range a {
	if v > x {
		f()
		break
	}
}
import "slices"
if slices.ContainsFunc(a, func(i int) bool {
	return i > x
}) {
	f()
}
(when (seq (filter #(> % x) a)) (f))
unsigned i;
for (i = 0; i < sizeof(a) / sizeof(a[0]); ++i) {
	if (a[i] > x) {
		f();
		break;
	}
}

New implementation...
< >
tkoenig