Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function arrayManipulations(input) {
- let arr = input.shift().split(' ').map(Number);
- while (input.length !== 0) {
- let command = input.shift().split(' ');
- if (command[0] === 'Add') {
- add(Number(command[1]));
- } else if (command[0] === 'Remove') {
- remove(Number(command[1]));
- } else if (command[0] === 'RemoveAt') {
- removeAt(Number(command[1]));
- } else if (command[0] === 'Insert') {
- insert(Number(command[1]), Number(command[2]));
- }
- }
- function add(num) {
- arr.push(Number(num));
- }
- function remove(num) {
- arr = arr.filter(x => x !== num);
- }
- function removeAt(num) {
- arr.splice(num, 1);
- }
- function insert(num, i) {
- arr.splice(i, 0, num);
- }
- console.log(arr.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement