Skip to content

Instantly share code, notes, and snippets.

@rema7
Created July 13, 2019 08:16
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/4323051d079c57c45801930b9ff55cd9 to your computer and use it in GitHub Desktop.
Save rema7/4323051d079c57c45801930b9ff55cd9 to your computer and use it in GitHub Desktop.
function drawRating(vote) {
let max = 5
vote = vote > 100 ? 100 : vote <= 0 ? 1 : vote
const rest = Math.floor((100-vote)/20)
let start = []
for (let i = 0; i < max - rest; i++) {
start.push('*')
}
for (let i = max - rest; i < 5; i++) {
start.push('-')
}
return start
}
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