Преглед изворни кода

⚡️ use array.reduce() instead of Math.max(...)

https://stackoverflow.com/a/53654364/3019419
jmacura пре 4 година
родитељ
комит
d06384043a
1 измењених фајлова са 3 додато и 4 уклоњено
  1. 3 4
      src/adjuster/adjuster.service.ts

+ 3 - 4
src/adjuster/adjuster.service.ts

@@ -54,10 +54,9 @@ export class AdjusterService {
               max = a.aggregate;
             }
           });*/
-          const max = Math.max(
-            ...attractivenessData.map((a) => a.aggregate),
-            0
-          );
+          const max = attractivenessData.reduce((a, b) =>
+            a.aggregate > b.aggregate ? a : b
+          ).aggregate;
           const normalizer = 1 / max;
           attractivenessData.forEach((a) => {
             a.aggregate *= normalizer;