Skip to main content

Practice ยท 3 of 4

Callbacks with a Predicate

Implement a small algorithm library: ``c /* applies fn to every element of arr (n elements) in place */ void map_i(int *arr, size_t n, int (*fn)(int)); /* counts elements where pred returns nonzero */ size_t count_if(const int *arr, size_t n, int (*pred)(int)); /* removes elements failing pred (keeping order); returns new length */ size_t filter_i(int *arr, size_t n, int (*pred)(int)); ``

Difficulty: intermediate

Back to lesson: Practice: Comparator Gym