Sha256: e144273c6914cd5a91a8cf28738f6c750d1f10bdbf9751cd34f4a0229d91cc1e

Contents?: true

Size: 1.08 KB

Versions: 396

Compression:

Stored size: 1.08 KB

Contents

struct House {

    private static let pieces = [
        ["the horse and the hound and the horn", "that belonged to"],
        ["the farmer sowing his corn", "that kept"],
        ["the rooster that crowed in the morn", "that woke"],
        ["the priest all shaven and shorn", "that married"],
        ["the man all tattered and torn", "that kissed"],
        ["the maiden all forlorn", "that milked"],
        ["the cow with the crumpled horn", "that tossed"],
        ["the dog", "that worried"],
        ["the cat", "that killed"],
        ["the rat", "that ate"],
        ["the malt", "that lay in"],
        ["the house that Jack built"]
    ]

    static func recite() -> String {
        return (1...pieces.count).map { line($0) }.joined(separator: "\n\n")

    }

    private static func line(_ number: Int) -> String {
        let startIndex = pieces.count - number
        let endIndex = pieces.count
        let selectedPieces = pieces[startIndex ..< endIndex]
        let text = selectedPieces.map { $0.joined(separator: "\n") }.joined(separator: " ")

        return "This is \(text)."
    }

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.179 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.178 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.177 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.176 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.175 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.174 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.173 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.172 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.171 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.170 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.169 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.167 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.166 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.165 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.164 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.163 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.162 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.161 tracks/swift/exercises/house/Sources/HouseExample.swift
trackler-2.2.1.160 tracks/swift/exercises/house/Sources/HouseExample.swift