Guest User

oddsEvens

a guest
Dec 28th, 2021
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. let input = [
  2. '5',
  3. '4',
  4. '3',
  5. '2',
  6. '5',
  7. '2'
  8. ];
  9.  
  10. let print = this.print || console.log;
  11. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  12.  
  13. let n = +gets();
  14. const oddLines = [];
  15. const evenLines = [];
  16.  
  17. for(i = 1; i <= n; i++){
  18. if(i % 2 === 0){
  19. evenLines.push(+gets());
  20. }else{
  21. oddLines.push(+gets());
  22. }
  23. }
  24. console.log(evenLines, oddLines)
  25.  
  26. function product(array){
  27. let total = 1;
  28. for(let i = 0; i <= array.lenght; i++){
  29. if(isNaN(array[i])){
  30. continue;
  31. }else{
  32. total *= Number(array[i]);
  33. }
  34. }
  35. return total;
  36. }
  37.  
  38.  
  39. let productOfEven = product(evenLines);
  40. let productOfOdds = product(oddLines);
  41.  
  42. console.log(productOfEven,productOfOdds)
  43. if(productOfEven === productOfOdds){
  44. print(`yes ${productOfEven}`)
  45. }else{
  46. print(`no ${productOfOdds} ${productOfEven}`)
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment