Last active
March 29, 2017 14:58
-
-
Save fitomad/0f0651d97e92b9783b03f2de8326d68a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Array where Element: Comparable | |
{ | |
/** | |
Saludamos en orden a todos los integrantes del `Array`. | |
*/ | |
public func saluteAllElements() -> Void | |
{ | |
let sorted_elements: [Element] = self.sorted(by: { $0 < $1 }) | |
sorted_elements.forEach({ print("¡Hola \($0)!") }) | |
} | |
} | |
extension Array where Element == Int | |
{ | |
/// Obtiene el valor de la suman de todos | |
/// los número del `Array` | |
public var sum: Element | |
{ | |
return self.reduce(0) { $0 + $1 } | |
} | |
} | |
let nombres: [String] = [ "Hugo", "Carlos", "Isabel", "Susana", "Juan", "Paloma" ] | |
let numeros: [Int] = [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ] | |
nombres.saluteAllElements() | |
/* | |
¡Hola Carlos! | |
¡Hola Hugo! | |
¡Hola Isabel! | |
¡Hola Juan! | |
¡Hola Paloma! | |
¡Hola Susana! | |
*/ | |
print("Esta serie de Fibonacci suma \(numeros.sum)") | |
/* | |
Esta serie de Fibonacci suma 143 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment