Skip to content

Instantly share code, notes, and snippets.

@rema7
Created July 11, 2019 10:01
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 rema7/7a0d4d426fb36dd8a1084e06e586bac3 to your computer and use it in GitHub Desktop.
Save rema7/7a0d4d426fb36dd8a1084e06e586bac3 to your computer and use it in GitHub Desktop.
function sequences(n) {
let result = [];
if (n < 1) {
return result
}
result.push('1')
for (let i = 1; i<n; i++) {
prev = result[i-1].split('-').reverse().join('-')
result.push(i%2 ? `${i+1}-${prev}` : `${prev}-${i+1}`)
}
result.forEach((r) => console.log(r));
return result;
}
sequences(7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment