JSFiddle - React, Tailwind, and code Playground
JavaScript
var hash = function(x) {
var h = 0
for (var i = 0; i < x.length; i++) {
h += x.charCodeAt(i)
h ^= h << 5
h ^= h >> 3
h ^= h << 13
h &= 0xffff
}
return h
}
var listener = function(e) {
var accelerationString = JSON.stringify(e.acceleration)
var hashed = hash(accelerationString)
alert(hashed % 2)
window.removeEventListener("devicemotion", listener, true)
}
window.addEventListener("devicemotion", listener, true);