Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function arrayManipulations(arr) {
- let array = arr.shift().split(' ')
- arr.forEach(line => {
- let [command, ...args] = line.split(' ');
- if (command === 'Add') {
- array.push(args[0]);
- } else if (command === 'Remove') {
- if (array.indexOf(args[0]) !== -1) {
- array.splice(array.indexOf(args[0]), 1);
- }
- } else if (command === 'RemoveAt') {
- array.splice(args[0], 1)
- } else if (command === 'Insert') {
- array.splice(args[1], 0, args[0]);
- }
- })
- return array.map(Number).join(' ');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement