Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function exam(args) {
- const materials = args.shift().split(', ');
- const isFind = (matArr, material) => {
- const isMaterialFind = matArr.find((mat) => mat === material);
- return isMaterialFind;
- };
- const findPosition = (matArr, material) => {
- const index = matArr.indexOf(material);
- return index;
- };
- args.forEach((elelement) => {
- const [command, material] = elelement.split(' - ');
- const isFound = isFind(materials, material);
- switch (command) {
- case 'Collect':
- if (isFound === undefined) {
- materials.push(material);
- }
- break;
- case 'Drop':
- if (isFound !== undefined) {
- materials.splice(findPosition(materials, material), 1);
- }
- break;
- case 'Combine Items':
- const [oldItem, newItem] = material.split(':');
- const findOldEx = isFind(materials, oldItem);
- if (findOldEx !== undefined) {
- const oldItemIndex = findPosition(materials, oldItem);
- materials.splice(oldItemIndex + 1, 0, newItem);
- }
- break;
- case 'Craft!':
- console.log(materials.join(', '));
- break;
- case 'Renew':
- if (isFound !== undefined) {
- materials.splice(findPosition(materials, material), 1);
- materials.push(material);
- }
- break;
- }
- });
- }
Add Comment
Please, Sign In to add comment