Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr){
- let contacts = arr.shift().split(' ');
- for(let i = 0; i < arr.length; i++){
- let [cmd, second, third] = arr[i].split(' ');
- if(cmd === 'Add'){
- if(!contacts.includes(second)){
- contacts.push(second);
- }else{
- if(0 <= +(third) && +(third) < contacts.length){
- contacts.splice(+(third), 0, second);
- }
- }
- }
- if(cmd === 'Remove'){
- if(0 <= +(second) && +(second) < contacts.length){
- contacts.splice(+(second), 1);
- }
- }
- if(cmd === 'Export'){
- let exported = [];
- exported = contacts.slice(+(second), +(third)||contacts.length);
- console.log(exported.join(' '));
- }
- if(cmd === 'Print' && second === 'Normal'){
- console.log(`Contacts: ${contacts.join(' ')}`)
- return;
- }
- if(cmd === 'Print' && second === 'Reversed'){
- console.log(`Contacts: ${contacts.reverse().join(' ')}`);
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement