diff --git a/05_hash_tables/ts/01_price_of_groceries.ts b/05_hash_tables/ts/01_price_of_groceries.ts new file mode 100644 index 00000000..1c5228a6 --- /dev/null +++ b/05_hash_tables/ts/01_price_of_groceries.ts @@ -0,0 +1,11 @@ +interface HashTable { + [key: string]: T; +} + +const book: HashTable = {}; + +book['apple'] = 0.67; +book['milk'] = 1.49; +book['avocado'] = 1.49; + +console.log(book); // { apple: 0.67, milk: 1.49, avocado: 1.49 } \ No newline at end of file diff --git a/05_hash_tables/ts/02_check_voter.ts b/05_hash_tables/ts/02_check_voter.ts new file mode 100644 index 00000000..1369b3dd --- /dev/null +++ b/05_hash_tables/ts/02_check_voter.ts @@ -0,0 +1,18 @@ +interface HashTable { + [key: string]: T; +} + +const voted: HashTable = {}; + +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! \ No newline at end of file