Advertisement
WindFell

Travel Investigation

Oct 3rd, 2018
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let companies = input.shift()
  3.         .split(input.shift());
  4.     let sentences = input.map(s => s.toLowerCase());
  5.     let valid = [];
  6.     let invalid = [];
  7.     let count = 1;
  8.    
  9.     sentences
  10.         .forEach(s => {
  11.             let isValid = true;
  12.             companies
  13.                 .forEach(c => {
  14.                     if (s.indexOf(c) < 0) {
  15.                         isValid = false;
  16.                     }
  17.                 });
  18.             isValid ? valid.push(s) : invalid.push(s);
  19.         });
  20.    
  21.     if (valid.length > 0) {
  22.         console.log("ValidSentences");
  23.         valid.forEach(s => {
  24.             console.log(`${count++}. ${s}`);
  25.         });
  26.     }
  27.    
  28.     if (valid.length > 0 && invalid.length > 0) {
  29.         console.log("=".repeat(30));
  30.     }
  31.    
  32.     if (invalid.length > 0) {
  33.         count = 1;
  34.         console.log("InvalidSentences");
  35.         invalid.forEach(s => {
  36.             console.log(`${count++}. ${s}`);
  37.         });
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement