Dont use memory to allocate a list
import java.util.Arrays; import static java.util.stream.IntStream.of; interface Kata { static int[] remove(int[] array, int[] exclude) { Arrays.sort(exclude); return of(array).filter(i -> Arrays.binarySearch(exclude, i) < 0).toArray(); } }
- import java.util.Arrays;
- import static java.util.stream.IntStream.of;
- interface Kata {
static int[] remove(int[] array, int[] exclude) {var forRemoval = of(exclude).boxed().toList();return of(array).filter(i -> !forRemoval.contains(i)).toArray();}- static int[] remove(int[] array, int[] exclude) {
- Arrays.sort(exclude);
- return of(array).filter(i -> Arrays.binarySearch(exclude, i) < 0).toArray();
- }
- }
Algorithms
Logic
Search
Strings
Data Types
fun findFirstSubString(string: String, subString: String): Int? = subString.takeIf { it.isNotEmpty() }?.let { string.indexOf(subString) }.takeIf { it != -1 }
- fun findFirstSubString(string: String, subString: String): Int? =
if (subString.isEmpty()) nullelse string.indexOf(subString).let { if (it == -1) null else it }- subString.takeIf { it.isNotEmpty() }?.let { string.indexOf(subString) }.takeIf { it != -1 }