Skip to content

Instantly share code, notes, and snippets.

@andrit
Created July 10, 2018 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrit/62e6673247943ff88ac4246e212d580a to your computer and use it in GitHub Desktop.
Save andrit/62e6673247943ff88ac4246e212d580a to your computer and use it in GitHub Desktop.
function* repeatedArray(arr) {
  let index = 0;
  while (true) {
    yield arr[index++ % arr.length];
  }
}

const lifts = ['squat', 'bench', 'deadlift', 'press'];
const nextLiftGenerator = repeatedArray(lifts);

const numWeeks = 3;
const daysPerWeek = 6;

const totalNumSessions = numWeeks * daysPerWeek;

// This creates an empty array of totalNumSessions length
// for me to map over
const cycle = [...Array(totalNumSessions)].map(() => ({
  lift: nextLiftGenerator.next().value,
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment