Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(params){
- params.pop();
- let kidList=params.shift().split(`&`);
- for (let param of params) {
- let tokens=param.split(` `);
- let command=tokens[0];
- let kidName=tokens[1];
- let index=kidList.indexOf(kidName);
- if(command===`Bad`&&index===-1){
- kidList.unshift(kidName);
- }else if(command===`Good`&&index!==-1){
- kidList.slice(index,1)
- }else if(command===`Rename`&&index!==-1){
- let newName=tokens[2];
- kidList[index]=newName
- }else if(command===`Rearrange`&&index!==-1){
- let kid=kidList.splice(index,1)
- kidList.push(kid)
- }
- }
- console.log(kidList.join(`, `))
- }
- solve([
- `Peter&George&Mike`,
- `Bad Joshua`,
- `Good Peter`,
- `Finished`,
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement