Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- /*Write a function that keeps track of guests that are going to a house party.
- You will be given an array of strings. Each string will be one of the following:
- - "{name} is going!"
- - "{name} is not going!"
- If you receive the first type of input, you have to add the person if he/she is not in the list (If he/she is in the list print: "{name} is already in the list!").
- If you receive the second type of input, you have to remove the person if he/she is in the list (if not print: "{name} is not in the list!").
- At the end print all the guests each on a separate line.*/
- function myFunct(arrayOfStrings) {
- let arr = arrayOfStrings;
- let guestList = [];
- let not_going = [];
- let going = [];
- for (el of arr) {
- if (el.includes('not')) {
- not_going.push(el.split(' ')[0]);
- }
- else {
- going.push(el.split(' ')[0]);
- }
- }
- for (i = 0; i < going.length; i++) {
- if (!guestList.includes(going[i])) {
- guestList.push(going[i])
- } else {
- console.log(going[i], "is already in the list!");
- }
- }
- for (i = 0; i < not_going.length; i++) {
- if (guestList.includes(not_going[i])) {
- let removeThisGuestIndex = guestList.indexOf(not_going[i]);
- guestList.splice(removeThisGuestIndex, 1)
- } else {
- console.log(not_going[i], "is not in the list!")
- }
- }
- console.log(guestList.join('\n'))
- }
Add Comment
Please, Sign In to add comment