Sha256: b4c95fff8a037994d7c1e5157d798e263674c8fd3b86ea71a11fba5323deda84

Contents?: true

Size: 1.27 KB

Versions: 118

Compression:

Stored size: 1.27 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) {
    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, end) {
    let lines = [];
    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

118 entries across 118 versions & 1 rubygems

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