Skip to content

Commit 8a4695d

Browse files
committed
2 parents 3ec8d58 + fa6c9d4 commit 8a4695d

File tree

1 file changed

+12
-6
lines changed
  • Lessons/09-Functional-ProgrammingPt.1/assignments

1 file changed

+12
-6
lines changed

Lessons/09-Functional-ProgrammingPt.1/assignments/activity.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

22
## In Class Activity
33

4-
### Individually
4+
### Individually or In a team create a playground or Repl.it to work on the following:
5+
6+
#### Resources:
7+
- [map documentation](https://developer.apple.com/documentation/swift/array/3017522-map)
8+
- [filter documentation](https://developer.apple.com/documentation/swift/sequence/3018365-filter)
9+
- [reduce documentation](https://developer.apple.com/documentation/swift/array/2298686-reduce)
510

611
1. Here is an imperative version of a function called `doubleIt` that takes an array of numbers and returns a new array after doubling every item in the initial array:
712

@@ -19,8 +24,6 @@ func doubleIt(inputArray: Array<Int>) {
1924
doubleIt(inputArray: [1,2,3]) // [2,4,6]
2025
```
2126

22-
**TODO:**
23-
2427
Code the declarative (FP) version of `doubleIt`so that it achieves the same result as the code above by using the `map` function instead of the `for loop`
2528

2629
<!--
@@ -38,11 +41,11 @@ doubleIt(inputArray: [1,2,3]) // [2,4,6]
3841

3942
2. Suppose we have an array containing strings representing the contents of a directory:
4043

41-
let exampleFiles = ["README.md", "HelloWorld.swift", "FlappyBird.swift"]
44+
`let exampleFiles = ["README.md", "HelloWorld.swift", "FlappyBird.swift"]`
4245

43-
Now suppose we want an array of all the .swift files. This is easy to compute with a simple loop. Use the HOF filter.
46+
Now suppose we want an array of all the .swift files. This is easy to compute with a simple loop. Use the HOF `filter`.
4447

45-
3. Define a function that sums all the integers in an array.
48+
3. Define a function that sums all the integers in an array. Use `reduce`
4649

4750
4. Suppose we have the following struct, consisting of a city’s name and population (measured in thousands of inhabitants):
4851

@@ -71,3 +74,6 @@ let cities = [paris, madrid, amsterdam, berlin]
7174
```
7275

7376
Print a list of cities with at least one million inhabitants, together with their total populations.
77+
78+
79+
*From: Chris Eidhof. “Functional Swift.” Apple Books*

0 commit comments

Comments
 (0)