Skip to content

Instantly share code, notes, and snippets.

@arturmkrtchyan
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturmkrtchyan/5b7bfa655ccebb1f9647 to your computer and use it in GitHub Desktop.
Save arturmkrtchyan/5b7bfa655ccebb1f9647 to your computer and use it in GitHub Desktop.
Functional vs. Imperative Programming
public boolean isPrime(final int number) {
return number > 1 &&
IntStream.rangeClosed(2, (int) Math.sqrt(number))
.noneMatch(index -> number % index == 0);
}
public boolean isPrime(final int number) {
for(int i = 2; i <= Math.sqrt(number); i++) {
if(number % i == 0) return false;
}
return number > 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment