Skip to content

Instantly share code, notes, and snippets.

@tapmodo
Last active December 6, 2018 00:58
Show Gist options
  • Save tapmodo/a3f2ab38a73f5bb26b909ae0fb8d0a6c to your computer and use it in GitHub Desktop.
Save tapmodo/a3f2ab38a73f5bb26b909ae0fb8d0a6c to your computer and use it in GitHub Desktop.
function containsExactHalvesSubarray(v) {
const hash = {}
v = v.sort((a,b) => parseInt(a)-parseInt(b));
v.forEach(i => {
if (i < 0)
if (hash[i]) hash[i][0] = true
else hash[i/2] = [null,true]
else
if (hash[i/2]) hash[i/2][1] = true
else hash[i] = [true,null]
})
return Object.keys(hash).every(key => hash[key][0] == hash[key][1])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment