Sha256: 713ed559b7f428ce87a97339375d48e100ad611fc4bdba2180ca0fa294742e4d

Contents?: true

Size: 1.53 KB

Versions: 47

Compression:

Stored size: 1.53 KB

Contents

const OBJECTS = [
    'house',
    'malt',
    'rat',
    'cat',
    'dog',
    'cow with the crumpled horn',
    'maiden all forlorn',
    'man all tattered and torn',
    'priest all shaven and shorn',
    'rooster that crowed in the morn',
    'farmer sowing his corn',
    'horse and the hound and the horn',
]

const ACTIONS = [
    'Jack built',
    'lay in',
    'ate',
    'killed',
    'worried',
    'tossed',
    'milked',
    'kissed',
    'married',
    'woke',
    'kept',
    'belonged to',
]

class House {
    static verse(verseNumber: number) {
        const lines = []
        const totalLines = verseNumber
        let itemIndex = verseNumber - 1
        for (let lineNumber = 1; lineNumber <= totalLines; lineNumber += 1) {
            let lineText = ''
            if (lineNumber === 1) {
                lineText += 'This is'
            } else {
                lineText += `that ${ACTIONS[itemIndex]}`
                itemIndex -= 1
            }

            lineText += ` the ${OBJECTS[itemIndex]}`
            if (lineNumber === totalLines) {
                lineText += ` that ${ACTIONS[itemIndex]}.`
            }
            lines.push(lineText)
        }
        return lines
    }

    static verses(start: number, end: number) {
        let lines: string[] = []
        for (let i = start; i <= end; i += 1) {
            const verseLines = House.verse(i)
            lines = lines.concat(verseLines)
            if (i < end) {
                lines.push('')
            }
        }
        return lines
    }
}

export default House

Version data entries

47 entries across 47 versions & 1 rubygems

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