You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| 6 % 2 | 0 |`let isEven = (number % 2 == 0)`|`true`| If a number is divisible by 2 it is *even*|
30
+
| 5 % 2 | 1 |`let isOdd = (number % 2 != 0)`|`true`| If a number is not divisible by 2 it is *odd*|
31
+
32
+
Alternatively, Swift's built in function .isMultiple(of:) can be used, i.e. 6.isMultiple(of: 2) will return true, 5.isMultiple(of: 2) will return false
31
33
32
34
## Solving fizz buzz
33
35
34
-
Now we can use the modulus operator `%` to solve fizz buzz.
36
+
Now we can use the modulus operator `%`or .isMultiple(of:) method to solve fizz buzz.
35
37
36
38
Finding numbers divisible by three:
37
39
38
-
| Modulus | ModulusResult | Swift Code| Swift CodeResult |
@@ -27,4 +27,4 @@ let amsterdam = (52.3702, 4.8952)
27
27
letnewYork=(40.7128,-74.0059)
28
28
29
29
// Google says it's 5857 km so our result is only off by 2km which could be due to all kinds of things, not sure how google calculates the distance or which latitude and longitude google uses to calculate the distance.
Copy file name to clipboardExpand all lines: Heap Sort/README.markdown
+1-1
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ As you can see, the largest items are making their way to the back. We repeat th
42
42
43
43
> **Note:** This process is very similar to [selection sort](../Selection%20Sort/), which repeatedly looks for the minimum item in the remainder of the array. Extracting the minimum or maximum value is what heaps are good at.
44
44
45
-
Performance of heap sort is **O(n lg n)** in best, worst, and average case. Because we modify the array directly, heap sort can be performed in-place. But it is not a stable sort: the relative order of identical elements is not preserved.
45
+
Performance of heap sort is **O(n log n)** in best, worst, and average case. Because we modify the array directly, heap sort can be performed in-place. But it is not a stable sort: the relative order of identical elements is not preserved.
0 commit comments