Skip to content

Instantly share code, notes, and snippets.

@stefanoschrs
Created December 3, 2018 09:51
Show Gist options
  • Save stefanoschrs/765a3bedd91b53374d76cf679f9cf8b5 to your computer and use it in GitHub Desktop.
Save stefanoschrs/765a3bedd91b53374d76cf679f9cf8b5 to your computer and use it in GitHub Desktop.
Flex grid fill last row
const W = 4
function fill(x) {
for(let i=0; i<x; i+=W){
for(let j=0; j<W && i + j < x; j++) {
process.stdout.write('x')
}
if (i < x - W && parseInt(i/W) === i/W) {
console.log()
}
}
for(let i=0; i<(W-x%W) && x % W !== 0; i++) {
process.stdout.write('o')
}
}
for(let i=1; i<=10; i++){
console.log(`>> ${i} <<`)
fill(i)
console.log()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment