Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function arrayModifier(input) {
- let numbers = input[0].split(' ').map(Number);
- for (let i = 1; input[i] != "end"; i++) {
- [command, index1, index2] = input[i].split(' ');
- if (command == "decrease") {
- for (let i = 0; i < numbers.length; i++) {
- numbers[i]--;
- }
- } else {
- if (command == "swap") {
- let value = numbers[index1];
- numbers[index1] = numbers[index2];
- numbers[index2] = value;
- } else {
- numbers[index1] *= numbers[index2];
- }
- }
- }
- console.log(numbers.join(", "));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement