momo3141

Page calculator

Jan 7th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let words = gets().split(', ');//най-важния ред от кода:)
  2. let wpPage = +gets();
  3. let key = gets();
  4. let currentPage = 1;
  5. let counter = 0
  6. let outPut = [] //Тука се съхраняват страниците
  7. for(let word of words){
  8.     if((word == key)){
  9.         outPut.push(currentPage)
  10.     }
  11.     counter ++
  12.     if (counter === wpPage){
  13.         currentPage++
  14.         counter = 0
  15.     }
  16.  
  17. }
  18. outPut.push(-1) // ако не е открита думата се пушва -1
  19. outPut = outPut.sort((a,b) => b-a) //сортира се низходящо
  20. console.log(outPut[0]);
Advertisement
Add Comment
Please, Sign In to add comment