Waste less time on Facebook — follow Brilliant.
×
Computer Science

Functional Programming

Concept Quizzes

Foldlist

     

Consider the function below which uses fold, and an anonymous helper function.

What is the output, when x = [1; 2; 3; 4; 5; 6]?

1
List.fold ~f:(fun a b -> a * b) ~init:1 x ;;

Use fold or reduce to find the greatest common divisor of all the positive integers in the following file.

Consider the following snippet written in OCaml:

1
2
3
let list_func our_list = 
    List.fold_left ~f:(fun first second -> second::first)
                   ~init:[] our_list;;

What is the output when the following list is input:

\([8; 2; 5; 5]\)

×

Problem Loading...

Note Loading...

Set Loading...