Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Weapon(input){
- let w = input.shift();
- let weapon = w.split("|");
- let command = input.shift();
- let arrEvenOdd=[];
- while(command !== 'Done'){
- if(command.includes('Move Right')){
- let num = command.split(" ");
- let indexR = +num[2];
- if (indexR <= weapon.length && indexR >= 0) {
- let val = weapon[indexR];
- weapon.splice(indexR+2, 0, val);
- weapon.splice(indexR, 1);
- }
- command = input.shift();
- }else if(command.includes('Move Left')){
- let num = command.split(" ");
- let indexL = +num[2];
- if (indexL > 0) {
- let val = weapon[indexL];
- weapon.splice(indexL-1, 0, val);
- weapon.splice(indexL+1, 1);
- }
- command = input.shift();
- }else if(command.includes('Odd')){
- for (let k = 0; k < weapon.length; k++) {
- if(k % 2 !== 0){
- arrEvenOdd.push(weapon[k]);
- }
- }
- command = input.shift();
- }else if(command.includes('Even')){
- for (let k = 0; k < weapon.length; k++) {
- if(k % 2 === 0){
- arrEvenOdd.push(weapon[k]);
- }
- }
- command = input.shift();
- }
- }
- if(arrEvenOdd.length>0){
- console.log(arrEvenOdd.join(' '));
- }
- console.log(`You crafted ${weapon.join('')}!`);
- }
- Weapon(['ri|As|er|hb|ng',
- 'Move Left 1',
- 'Move Right 2',
- 'Move Right 3',
- 'Move Left 2',
- 'Done']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement