Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cafeteria(array){
- let baristasArray = [];
- for (let index = 1; index <= parseInt(array[0]); index++) {
- let barista = {};
- barista['name'] = array[index].split(' ')[0];
- barista['shift'] = array[index].split(' ')[1];
- barista['drinks'] = array[index].split(' ')[2].split(',');
- baristasArray.push(barista);
- }
- for (let index = parseInt(array[0]) + 1; index < array.length; index++) {
- let commandArray = array[index].split(' / ');
- if (commandArray[0] === 'Closed') {
- break;
- } else if (commandArray[0] === 'Prepare') {
- for (let index = 0; index < baristasArray.length; index++) {
- if (baristasArray[index].name === commandArray[1]) {
- if (baristasArray[index].shift === commandArray[2] && baristasArray[index].drinks.includes(commandArray[3])) {
- console.log(baristasArray[index].name + ' has prepared a ' + commandArray[3] + ' for you!')
- } else {
- console.log(baristasArray[index].name + ' is not available to prepare a ' + commandArray[3] + '.')
- }
- }
- }
- } else if (commandArray[0] === 'Change Shift') {
- for (let index = 0; index < baristasArray.length; index++) {
- if (baristasArray[index].name === commandArray[1]) {
- baristasArray[index].shift = commandArray[2];
- console.log(baristasArray[index].name + ' has updated his shift to: ' + commandArray[2])
- }
- }
- } else if (commandArray[0] === 'Learn') {
- for (let index = 0; index < baristasArray.length; index++) {
- if (baristasArray[index].name === commandArray[1]) {
- if (baristasArray[index].drinks.includes(commandArray[2])) {
- console.log(baristasArray[index].name + ' knows how to make ' + commandArray[2] + '.');
- } else {
- baristasArray[index].drinks.push(commandArray[2]);
- console.log(baristasArray[index].name + ' has learned a new coffee type: ' + commandArray[2] + '.');
- }
- }
- }
- }
- }
- for (let index = 0; index < baristasArray.length; index++) {
- let name = baristasArray[index].name;
- let shift = baristasArray[index].shift;
- let drinks = baristasArray[index].drinks.join(', ');
- console.log('Barista: ' + name + ', Shift: ' + shift + ', Drinks: ' + drinks);
- }
- }
- cafeteria([
- '3',
- 'Alice day Espresso,Cappuccino',
- 'Bob night Latte,Mocha',
- 'Carol day Americano,Mocha',
- 'Prepare / Alice / day / Espresso',
- 'Change Shift / Bob / night',
- 'Learn / Carol / Latte',
- 'Learn / Bob / Latte',
- 'Prepare / Bob / night / Latte',
- 'Closed']
- );
Advertisement
Add Comment
Please, Sign In to add comment