name:
src/main/js/utils/Reducers.ts
-rw-r--r--
1895
1/**
2 * Helper classes for use in [].reduce(...).
3 */
4import { Complex } from "../models/common/Types";
5
6export class Reducers {
7 /**
8 * Find max of numbers when reducing.
9 * @param first - number.
10 * @param second - number.
11 */
12 static max(first: number, second: number) {
13 return Math.max(first, second);
14 }
15
16 /**
17 * Find min of numbers when reducing.
18 * @param first - number.
19 * @param second - number.
20 */
21 static min(first: number, second: number) {
22 return Math.min(first, second);
23 }
24
25 /**
26 * Adds two numbers values together as per the + operator.
27 *
28 * @param first - first value.
29 * @param second - second value.
30 */
31 static sum(first: number, second: number) {
32 return first + second;
33 }
34
35 /**
36 * Multiplies two number values together as per the * operator
37 * @param first - first value
38 * @param second - second value
39 */
40 static product(first: number, second: number) {
41 return first * second;
42 }
43
44 /**
45 * Performs logical && operation on two booleans.
46 * @param first - first value.
47 * @param second - second value.
48 */
49 static logicalAnd(first: boolean, second: boolean) {
50 return first && second;
51 }
52
53 /**
54 * Performs logical || operation on two booleans.
55 * @param first - first value.
56 * @param second - second value.
57 */
58 static logicalOr(first: boolean, second: boolean) {
59 return first || second;
60 }
61
62 /**
63 * Performs logical exclusive or operation on two booleans.
64 * @param first - first value.
65 * @param second - second value.
66 */
67 static logicalXOr(first: boolean, second: boolean) {
68 return (first && !second) || (!first && second);
69 }
70
71 /**
72 * Joins the first and second arrays.
73 * @param first - first array.
74 * @param second - second array.
75 */
76 static join(first: Array<Complex>, second: Array<Complex>) {
77 return [].concat(...first, ...second);
78 }
79}