@yamato-daiwa/es-extensions 1.5.7 → 1.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -49,6 +49,16 @@ function getRandomSubarray(targetArray, options = {}) {
|
|
|
49
49
|
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
+
if (options.minimalElementsCount >= targetArray.length) {
|
|
53
|
+
Logger_1.default.throwErrorAndLog({
|
|
54
|
+
errorInstance: new InvalidParameterValueError_1.default({
|
|
55
|
+
parameterName: "options.minimalElementsCount",
|
|
56
|
+
messageSpecificPart: "The minimal element's count of subarray must be less than elements count of initial array."
|
|
57
|
+
}),
|
|
58
|
+
title: InvalidParameterValueError_1.default.localization.defaultTitle,
|
|
59
|
+
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
52
62
|
minimalElementsCount = options.minimalElementsCount;
|
|
53
63
|
}
|
|
54
64
|
else {
|
|
@@ -79,10 +89,20 @@ function getRandomSubarray(targetArray, options = {}) {
|
|
|
79
89
|
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
80
90
|
});
|
|
81
91
|
}
|
|
92
|
+
if (options.maximalElementsCount > targetArray.length) {
|
|
93
|
+
Logger_1.default.throwErrorAndLog({
|
|
94
|
+
errorInstance: new InvalidParameterValueError_1.default({
|
|
95
|
+
parameterName: "options.maximalElementsCount",
|
|
96
|
+
messageSpecificPart: "The maximal elements count of subarray could not exceed the elements count of initial array."
|
|
97
|
+
}),
|
|
98
|
+
title: InvalidParameterValueError_1.default.localization.defaultTitle,
|
|
99
|
+
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
82
102
|
maximalElementsCount = options.maximalElementsCount;
|
|
83
103
|
}
|
|
84
104
|
else {
|
|
85
|
-
maximalElementsCount =
|
|
105
|
+
maximalElementsCount = targetArray.length > 1 ? targetArray.length - 1 : 1;
|
|
86
106
|
}
|
|
87
107
|
const elementsCountInResultSubarray = (0, getRandomInteger_1.default)({
|
|
88
108
|
minimalValue: minimalElementsCount,
|
|
@@ -43,6 +43,16 @@ export default function getRandomSubarray(targetArray, options = {}) {
|
|
|
43
43
|
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
+
if (options.minimalElementsCount >= targetArray.length) {
|
|
47
|
+
Logger.throwErrorAndLog({
|
|
48
|
+
errorInstance: new InvalidParameterValueError({
|
|
49
|
+
parameterName: "options.minimalElementsCount",
|
|
50
|
+
messageSpecificPart: "The minimal element's count of subarray must be less than elements count of initial array."
|
|
51
|
+
}),
|
|
52
|
+
title: InvalidParameterValueError.localization.defaultTitle,
|
|
53
|
+
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
54
|
+
});
|
|
55
|
+
}
|
|
46
56
|
minimalElementsCount = options.minimalElementsCount;
|
|
47
57
|
}
|
|
48
58
|
else {
|
|
@@ -73,10 +83,20 @@ export default function getRandomSubarray(targetArray, options = {}) {
|
|
|
73
83
|
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
74
84
|
});
|
|
75
85
|
}
|
|
86
|
+
if (options.maximalElementsCount > targetArray.length) {
|
|
87
|
+
Logger.throwErrorAndLog({
|
|
88
|
+
errorInstance: new InvalidParameterValueError({
|
|
89
|
+
parameterName: "options.maximalElementsCount",
|
|
90
|
+
messageSpecificPart: "The maximal elements count of subarray could not exceed the elements count of initial array."
|
|
91
|
+
}),
|
|
92
|
+
title: InvalidParameterValueError.localization.defaultTitle,
|
|
93
|
+
occurrenceLocation: "getRandomSubarray(targetArray, options)"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
76
96
|
maximalElementsCount = options.maximalElementsCount;
|
|
77
97
|
}
|
|
78
98
|
else {
|
|
79
|
-
maximalElementsCount =
|
|
99
|
+
maximalElementsCount = targetArray.length > 1 ? targetArray.length - 1 : 1;
|
|
80
100
|
}
|
|
81
101
|
const elementsCountInResultSubarray = getRandomInteger({
|
|
82
102
|
minimalValue: minimalElementsCount,
|