Advertisement
Guest User

Title Search

a guest
Feb 17th, 2022
160
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = ['peshoishere', '3', 'eho', 'piere', 'telerik'];
  2.  
  3. let print = this.print || console.log;
  4. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  5.  
  6. let arr = gets().split('');
  7. let num = Number(gets());
  8.  
  9.  
  10. for (let i = 0; i < num; i++) {
  11.     let arrMatch = gets().split('');
  12.     let arrTemp = [...arr];
  13.     let limiter = 0;
  14.  
  15.     for (let k = 0; k < arrMatch.length; k++) {
  16.         if (arrTemp.indexOf(arrMatch[k]) > -1) {
  17.             arrTemp[(arrTemp.slice(limiter).indexOf(arrMatch[k]) + limiter)] = ' ';
  18.             limiter = arrTemp.lastIndexOf(' ');
  19.         }
  20.     }
  21.    
  22.     arrTemp = arrTemp.join('').split(' ').join('');
  23.  
  24.     if (arrTemp.length === arr.length - arrMatch.length) {
  25.         arr = arrTemp.split('')
  26.         print(arrTemp);
  27.     } else {
  28.         print('No such title found!')
  29.     }
  30. }
Advertisement
RAW Paste Data Copied
Advertisement