DimiPetrov

Page Calculator

Jan 8th, 2021
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. const input = [
  2. ['Telerik', 'Java', 'CSS', 'JavaScript', 'PHP', 'HTML', 'CSS', 'Spring', 'Angular'],
  3. '2',
  4. 'CSS'
  5. ];
  6.  
  7. const print = this.print || console.log;
  8. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  9.  
  10. const arr = gets();
  11. const words = +gets();
  12. const keyword = gets();
  13. let index = -1;
  14.  
  15. for (let i = 0; i < arr.length; i++) {
  16. if (arr[i] == keyword) {
  17. index = i;
  18. }
  19. }
  20.  
  21. if (index > -1) {
  22. let page = Math.ceil((index + 1) / words);
  23. print(page);
  24. } else {
  25. print(-1);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment