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