function solution($list) { $acc = 1; $func = function ($item, $acc) { return $acc * $item; }; $cellItAll = map($list, function ($item) { //map return ceil($item); }); $leaveJustEven = filter($cellItAll, function ($item) { //filter return $item % 2 == 0; }); $multiplyKill = accumulate($leaveJustEven, $func, $acc); //reduce ###################################################### // one line solution // return accumulate(filter(map($list, function($item) { // return ceil($item); // }), function($item) { // return $item % 2 == 0; // }), function($item, $acc) { // return $acc * $item; // }, $acc); return $multiplyKill; }
function sumOfDoubleOdds($list) { return accumulate($list, function ($item, $acc) { if ($item % 2 === 1) { return $item * 2 + $acc; } else { return $acc; } }, 0); }
} // Report if ($output == REPORT) { open_report(); report_header(); $body_rows = array(); for ($i = 0; $row = sql_row_keyed($res, $i); $i++) { report_row($body_rows, $row); } output_body_rows($body_rows, $output_format); close_report(); } else { open_summary(); if ($nmatch > 0) { for ($i = 0; $row = sql_row_keyed($res, $i); $i++) { accumulate($row, $count, $hours, $report_start, $report_end, $room_hash, $name_hash); } do_summary($count, $hours, $room_hash, $name_hash); } else { // Excel doesn't seem to like an empty file with just a BOM, so give // it an empty row as well to keep it happy $values = array(); output_row($values, $output_format); } close_summary(); } } } if ($cli_mode) { exit(0); }
echo "\r\n"; } for ($i = 0; $row = grr_sql_row($res, $i); $i++) { // Récupération des données concernant l'affichage du planning du domaine get_planning_area_values($row[11]); if ($enable_periods == 'y') { // pour le décompte des créneaux accumulate_periods($row, $count1, $hours1, $report_start, $report_end, $room_hash1, $breve_description_hash1, "y"); $do_sum1 = 'y'; } else { // pour le décompte des heures accumulate($row, $count2, $hours2, $report_start, $report_end, $room_hash2, $breve_description_hash2, "y"); $do_sum2 = 'y'; } // pour le décompte des réservations accumulate($row, $count, $hours, $report_start, $report_end, $room_hash, $breve_description_hash, "y"); } // Décompte des heures (cas ou $enable_periods != 'y') if (isset($do_sum1)) { echo "\r\n" . html_entity_decode($vocab["summary_header"]) . "\r\n"; do_summary($count1, $hours1, $room_hash1, $breve_description_hash1, "n", "heure", "y"); } // Décompte des créneaux (cas ou $enable_periods == 'y') if (isset($do_sum2)) { echo "\r\n" . html_entity_decode($vocab["summary_header_per"]) . "\r\n"; do_summary($count2, $hours2, $room_hash2, $breve_description_hash2, "y", "heure", "y"); } // Décompte des réservations echo "\r\n\r\n\r\n" . html_entity_decode($vocab["summary_header_resa"]) . "\r\n"; do_summary($count, $hours, $room_hash, $breve_description_hash, "", "resa", "y"); }
} else { // Order by Start date/time, Area, Room $sql .= " ORDER BY 2,9,10"; } // echo "<p>DEBUG: SQL: <tt> $sql </tt></p>\n"; $res = sql_query($sql); if (!$res) { fatal_error(0, sql_error()); } $nmatch = sql_count($res); if ($nmatch == 0) { echo "<p class=\"report_entries\">" . get_vocab("nothing_found") . "</p>\n"; sql_free($res); } else { $last_area_room = ""; $last_date = ""; echo "<p class=\"report_entries\">" . $nmatch . " " . ($nmatch == 1 ? get_vocab("entry_found") : get_vocab("entries_found")) . "</p>\n"; for ($i = 0; $row = sql_row_keyed($res, $i); $i++) { if ($summarize & 1) { reporton($row, $last_area_room, $last_date, $sortby, $display); } if ($summarize & 2) { empty($enable_periods) ? accumulate($row, $count, $hours, $report_start, $report_end, $room_hash, $name_hash) : accumulate_periods($row, $count, $hours, $report_start, $report_end, $room_hash, $name_hash); } } if ($summarize & 2) { do_summary($count, $hours, $room_hash, $name_hash); } } } require_once "trailer.inc";