Files
grokking_algorithms/05_hash_tables/ts/02_check_voter.ts
2019-03-28 14:51:19 -07:00

18 lines
398 B
TypeScript

interface HashTable<T> {
[key: string]: T;
}
const voted: HashTable<boolean> = {};
function check_voter(name: string): void {
if (voted[name]) {
console.log('kick them out!');
} else {
voted[name] = true;
console.log('let them vote!');
}
}
check_voter("tom"); // let them vote!
check_voter("mike"); // let them vote!
check_voter("mike"); // kick them out!