Add ES6 Examples to all chapters (#38)
* add ES6 example for binary search * add ES6 example for selection sort * add ES6 example for countdown * add ES6 example for greet * add ES6 example for factorial * edit ES6 example for quicksort * add ES6 example for loop sum * add ES6 example for recursive sum * add ES6 example for recursive count * add ES6 example for recursive max * add ES6 example for price of groceries * add ES6 example for check voter * add ES6 example for breadth-first search * add ES6 example for dijkstras algorithm * edit ES6 example for dijkstras algorithm * edit ES6 example for set covering * add ES6 example for longest common subsequence
This commit is contained in:
committed by
Aditya Bhargava
parent
1a81d3e6b2
commit
ec2890a93d
8
05_hash_tables/ES6/01_price_of_groceries.js
Normal file
8
05_hash_tables/ES6/01_price_of_groceries.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const book = {};
|
||||
// an apple costs 67 cents
|
||||
book.apple = 0.67;
|
||||
// milk costs $1.49
|
||||
book.milk = 1.49;
|
||||
book.avokado = 1.49;
|
||||
|
||||
console.log(book); // { apple: 0.67, milk: 1.49, avocado: 1.49 }
|
||||
14
05_hash_tables/ES6/02_check_voter.js
Normal file
14
05_hash_tables/ES6/02_check_voter.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const voted = {};
|
||||
const checkVoter = (name) => {
|
||||
if (voted[name]) {
|
||||
console.log('kick them out!');
|
||||
} else {
|
||||
voted[name] = true;
|
||||
console.log('let them vote!');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
checkVoter('tom'); // let them vote!
|
||||
checkVoter('mike'); // let them vote!
|
||||
checkVoter('mike'); // kick them out!
|
||||
Reference in New Issue
Block a user