subject

How can I reduce the number of loops, possibly into one loop on my solution below? The logic is right and it passes all my test cases but it looks a bit verbose. const hourglassSum = (arr) => { let count = 1; const hourglass = []; const flatglass = []; let idx = 0; do { const idx2 = idx + 1; const idx3 = idx + 2; hourglass. push([ [arr[0][idx], arr[0][idx2], arr[0][idx3]], [0, arr[1][idx2], 0], [arr[2][idx], arr[2][idx2], arr[2][idx3]], ]); idx += 1; count += 1; } while (count 4 && count 8 && count 12 && count { const flattened = [].concat(...innerglass); const arrSum = flattened. reduce((a, b) => a + b, 0); flatglass. push(arrSum); }); return Math. max(...flatglass); };

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:00, ed72018373
Which law requires employers to provide safe working environments for their employees? a. civil rights act b. fair labor standards act c. occupational safety and health act d. wagner act
Answers: 1
image
Computers and Technology, 22.06.2019 23:00, cchotshot
Is an attack that relies on guessing the isns of tcp packets
Answers: 2
image
Computers and Technology, 23.06.2019 03:00, tay9122
Jason, samantha, ravi, sheila, and ankit are preparing for an upcoming marathon. each day of the week, they run a certain number of miles and write them into a notebook. at the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day. write a program to them analyze their data. your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. furthermore, your program must contain at least the following functions: a function to read and store the runners’ names and the numbers of miles run each day; a function to find the total miles run by each runner and the average number of miles run each day; and a function to output the results. (you may assume that the input data is stored in a file and each line of data is in the following form: runnername milesday1 milesday2 milesday3 milesday4 milesday5 milesday6 milesday7.)
Answers: 3
image
Computers and Technology, 23.06.2019 14:00, LuvIsRage2
Technician a says that with self-adjusting clutch systems, the release bearing constantly rotates. technician b says that the ball bearing portion of the release bearing should be lubricated with high-temperature grease during routine maintenance. which technician is correct?
Answers: 2
You know the right answer?
How can I reduce the number of loops, possibly into one loop on my solution below? The logic is righ...

Questions in other subjects:

Konu
Business, 18.09.2019 09:30