date-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output. The result of update-if should be a list of items such that if x is in xs and (f x) is true, then (g x) is in the list. The output list's elements should keep the input list's items in the same relative order. For example (update-if even? add1 '(1 2 3 4)) shou
Write a recursive Racket function "update-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output. The result of update-if should be a list of items such that if x is in xs and (f x) is true, then (g x) is in the list. The output list's elements should keep the input list's items in the same relative order.
For example (update-if even? add1 '(1 2 3 4)) should evaluate to '(3 5) because 2 and 4 make even? true and add1 turns 2 and 4 into 3 and 5.
Step 1: Recursive Racket function "update-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output.
Step by step
Solved in 2 steps