@@ -98,7 +98,7 @@ Creates an array with all nil values removed.
98
98
$.compact ([3 , nil , 4 , 5 ])
99
99
=> [3 , 4 , 5 ]
100
100
101
- $.compact ([nil , nil ]) as NSObject[ ]
101
+ $.compact ([nil , nil ]) as [NSObject ]
102
102
=> []
103
103
```
104
104
@@ -268,7 +268,7 @@ result
268
268
=> 1
269
269
```
270
270
271
- ### first - ` $.first(array: AnyObject[ ]) `
271
+ ### first - ` $.first(array: [AnyObject ]) `
272
272
273
273
Gets the first element in the array.
274
274
@@ -291,7 +291,7 @@ $.groupBy(["strings", "with", "different", lengths"], callback: {$0.characters.c
291
291
=> [7: [" strings" , " lengths" ], 9: [" different" ], 4: [" With" ]]
292
292
```
293
293
294
- ### second - `$.second(array: AnyObject[ ])`
294
+ ### second - `$.second(array: [AnyObject ])`
295
295
296
296
Gets the second element in the array.
297
297
@@ -339,13 +339,13 @@ NSURL(string: "https://apple.com/swift/")?.lastPathComponent
339
339
Flattens a nested array of any depth.
340
340
341
341
```swift
342
- $.flatten ([[3 ], 4 , 5 ]) as Int []
342
+ $.flatten ([[3 ], 4 , 5 ])
343
343
=> [3 , 4 , 5 ]
344
344
345
- $.flatten ([[3 ], " Hello" , 5 ]) as NSObject[]
345
+ $.flatten ([[3 ], " Hello" , 5 ]) as [NSObject]
346
346
=> [3 , " Hello" , 5 ]
347
347
348
- $.flatten ([[[3 ], 4 ], 5 ]) as Int []
348
+ $.flatten ([[[3 ], 4 ], 5 ])
349
349
=> [3 , 4 , 5 ]
350
350
```
351
351
@@ -571,7 +571,7 @@ $.reduce([1, 2, 3], initial: 0) { (total, element) in
571
571
Returns a sample item from the array
572
572
573
573
```swift
574
- let arr : Int [] = [2 , 1 , 2 , 3 , 4 ]
574
+ let arr = [2 , 1 , 2 , 3 , 4 ]
575
575
$.contains (arr, value : $.sample (arr))
576
576
=> true
577
577
```
@@ -593,6 +593,21 @@ $.sequence((0..20).by(5))
593
593
$.sequence (" abc" )
594
594
=> [" a" , " b" , " c" ]
595
595
```
596
+
597
+ ### sum - `$.sum `
598
+
599
+ Returns the sum of elements in the array
600
+
601
+ ```swift
602
+ let arr = [1 , 2 , 3 ]
603
+ $.sum (arr)
604
+ => 6
605
+
606
+ let floatingNums = [1.5 , 2.5 , 3.1 ]
607
+ $.sum (floatingNums)
608
+ => 7.1
609
+ ```
610
+
596
611
### remove - `$.remove `
597
612
598
613
Removes an element from array.
@@ -1018,7 +1033,7 @@ let fun = $.bind({ (names: String...) -> String in
1018
1033
let people = $.join (names, separator : " from " )
1019
1034
return " Hello \( people ) "
1020
1035
}, " Ankur" , " Swift" )
1021
- $.times (2 , function : fun) as String [ ]
1036
+ $.times (2 , function : fun) as [ String ]
1022
1037
=> [" Hello Ankur from Swift" , " Hello Ankur from Swift" ]
1023
1038
```
1024
1039
0 commit comments