Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> Page Calculator
- const input = ['Telerik, Java, CSS, JavaScript, PHP, HTML, CSS, Spring, Angular', '5', 'CSS'];
- const print = this.print || console.log;
- const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- // Write a program that accepts an array of words, a value representing words per page and a keyword and
- // outputs on which page the keyword can be found.
- // If the word is not in the list print -1.
- const wordsArr = gets().split(', '); // ['Telerik', 'Java','CSS','JavaScript','PHP','HTML','CSS','Spring','Angular']
- const wordsPerPage = +gets(); // 2
- const keyWord = gets(); // CSS
- let whichIndex = 0;
- let whichPage = 0;
- for (let i = 0; i < wordsArr.length; i++) {
- if (keyWord === wordsArr[i]) {
- whichIndex = i + 1;
- }
- }
- // print(whichIndex); // 7
- whichPage = whichIndex / wordsPerPage;
- print(Math.ceil(whichPage));
Advertisement
Add Comment
Please, Sign In to add comment