Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function phoneShop(input) {
- let phones = input.shift().split(', ');
- while (input[0] !== 'End') {
- let [command, phone] = input.shift().split(' - ');
- if (command === 'Add' && !phones.includes(phone)) {
- phones.push(phone);
- } else if (command === 'Remove' && phones.includes(phone)) {
- phones.splice(phones.indexOf(phone, 1));
- } else if (command === 'Bonus phone') {
- let [oldPhone, newPhone] = phone.split(':');
- if (phones.includes(oldPhone)) {
- phones.splice(phones.indexOf(oldPhone) + 1, 0, newPhone);
- }
- } else if (command === 'Last' && phones.includes(phone)) {
- phones.push(phone);
- phones.splice(phones.indexOf(phone), 1);
- }
- }
- console.log(phones.join(', '));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement