romarioagros

Untitled

Sep 11th, 2020
855
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumElem(arr) {
  2.   let result = arr.reduce(function (sum, elem) {
  3.     return sum + elem;
  4.   }, 0);
  5.   return result;
  6. }
  7.  
  8. function max(list) {
  9.   return list.reduce((a, b) => (a > b ? a : b));
  10. }
  11.  
  12. function hourglassSum(arr) {
  13.   sumsOfElements = [];
  14.   for (let i = 0; i < 4; i++) {
  15.     for (let j = 0; j < 4; j++) {
  16.      
  17.       let one = arr[i]
  18.         .slice(j, j + 3)
  19.         .concat(arr[i + 1][j + 1])
  20.         .concat(arr[i + 2].slice(j, j + 3));
  21.       console.log(one);
  22.       let sumFigures = sumElem(one);
  23.       sumsOfElements.push(sumFigures);
  24.  
  25.     }
  26.   }
  27.   console.log(sumsOfElements);
  28.   let MaxElent = max(sumsOfElements);
  29.   return MaxElent;
  30. }
  31.  
  32. let arr = [
  33.   [-9, -9, -9, 1, 1, 1],
  34.   [0, -9, 0, 4, 3, 2],
  35.   [9, -9, -9, 1, 2, 3],
  36.   [0, 0, 8, 6, 6, 0],
  37.   [0, 0, 0, -2, 0, 0],
  38.   [0, 0, 1, 2, 4, 0],
  39. ];
  40. let arr2 = arr.map(Number);
  41.  
  42.  
  43.  
  44. console.log(hourglassSum(arr));
RAW Paste Data