Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let newArr = [];
- for (let element of arr) {
- let command = element.split(' ');
- let name = command[0];
- if (command.length === 3) {
- if (newArr.includes(name)) {
- console.log(`${name} is already in the list!`);
- } else{
- newArr.push(name);
- }
- } else if (command.length === 4) {
- if (newArr.includes(name)) {
- newArr.filter(names => names !== name);
- } else{
- console.log(`${name} is not in the list!`);
- }
- }
- }
- return newArr.join(`\n`)
- }
- console.log(solve(['Allie is going!', 'George is going!', 'John is not going!', 'George is not going!']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement