Skip to content

Instantly share code, notes, and snippets.

@lynn

lynn/bumpy.js Secret

Last active February 22, 2019 17:53
Show Gist options
  • Save lynn/f57bdb8f4e53fe36b914377bb7ba1dc8 to your computer and use it in GitHub Desktop.
Save lynn/f57bdb8f4e53fe36b914377bb7ba1dc8 to your computer and use it in GitHub Desktop.
var code = document.getElementById('code'); code.addEventListener('keyup', e => {
const v = code.value
const d = document.getElementById('debug')
if (v.length >= 2) {
for (var i = 0; i < v.length - 2; i++) {
if (! ((v[i]<v[i+1]&&v[i+1]>v[i+2]) || (v[i]>v[i+1]&&v[i+1]<v[i+2]))) {
d.value = 'Not bumpy! ' + v[i] + v[i+1] + v[i+2]
return
}
}
const ascii = new Array(95).fill(0).map((x,i)=>String.fromCharCode(i+32))
if (v[v.length-2] < v[v.length-1]) {
d.value = 'Next: ' + ascii.filter(c => v[v.length-1] > c).join``
} else {
d.value = 'Next: ' + ascii.filter(c => v[v.length-1] < c).join``
}
} else { d.value = '' }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment