Lesson 10 of 15

Lists

Lists

F# lists are immutable, singly-linked sequences written with [ and ], elements separated by ;:

let nums = [1; 2; 3; 4; 5]

You can use ranges:

let oneToTen = [1..10]

Common List functions:

List.length [1; 2; 3]       // 3
List.head [10; 20; 30]      // 10
List.tail [10; 20; 30]      // [20; 30]
List.sum [1; 2; 3; 4; 5]    // 15
List.rev [1; 2; 3]          // [3; 2; 1]

Your Task

Create a list nums containing [10; 20; 30; 40; 50]. Print its length, its first element, and its sum on separate lines.

JS Transpiler loading...
Loading...
Click "Run" to execute your code.