Last active
October 11, 2016 15:34
-
-
Save pomle/f931036d3a4e31f4c61d13d99851f849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let map; | |
function setup(phone1, phone2) { | |
map[phone1] = phone2; | |
map[phone2] = phone1; | |
} | |
function teardown(phone1, phone2) { | |
delete map[phone1]; | |
delete map[phone2]; | |
} | |
function print(map) { | |
println('======'); | |
Object.keys(map).forEach(k => { | |
const v = map[k]; | |
println(`${k} >> ${v}`); | |
}); | |
} | |
function println(str) { | |
process.stdout.write(str + '\n'); | |
} | |
map = Object.create(null); | |
setup('A', 'B'); | |
print(map); | |
/* A and B can reach each other */ | |
setup('A', 'C'); | |
print(map); | |
/* A can reach C, (ok) | |
B can reach A, (bad) | |
C can reach A, (ok) | |
but A can not reach B (orphan mapping) */ | |
teardown('A', 'B'); | |
print(map); | |
/* C can reach A only, and is now only orphan mapping. */ |
Author
pomle
commented
Oct 11, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment