kstoyanov

01. Arithmephile js fundametals exam

Jul 22nd, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   let maxProduct = Number.NEGATIVE_INFINITY;
  3.   const arrOfNumbers = args.map(Number);
  4.  
  5.   arrOfNumbers.forEach((el, i) => {
  6.     if (el >= 0 && el <= 9 && i + el < arrOfNumbers.length) {
  7.       let product = 1;
  8.       for (let j = i + 1; j <= i + el; j++) product *= arrOfNumbers[j];
  9.  
  10.       if (product > maxProduct) {
  11.         maxProduct = product;
  12.       }
  13.     }
  14.   });
  15.  
  16.   console.log(maxProduct);
  17. }
Add Comment
Please, Sign In to add comment