math-exercises 3.0.71 → 3.0.72
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.
- package/lib/exercises/math/probaStat/stats1var/median.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/stats1var/median.js +2 -11
- package/lib/exercises/math/probaStat/stats1var/medianList.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/stats1var/medianList.js +2 -10
- package/lib/exercises/math/probaStat/stats1var/quartilesList.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/stats1var/quartilesList.js +3 -9
- package/lib/math/utils/stats/median.d.ts +2 -0
- package/lib/math/utils/stats/median.d.ts.map +1 -0
- package/lib/math/utils/stats/median.js +39 -0
- package/lib/playground.d.ts.map +1 -1
- package/lib/playground.js +2 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"median.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/stats1var/median.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"median.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/stats1var/median.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,QAAQ,EAWT,MAAM,sBAAsB,CAAC;AAG9B,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAmFF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,CAYjD,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randint } from "../../../../math/utils/random/randint.js";
|
|
2
|
+
import { median } from "../../../../math/utils/stats/median.js";
|
|
2
3
|
import { shuffle } from "../../../../utils/alea/shuffle.js";
|
|
3
4
|
import { dollarize } from "../../../../utils/latex/dollarize.js";
|
|
4
5
|
import { mdTable } from "../../../../utils/markdown/mdTable.js";
|
|
@@ -16,17 +17,7 @@ Calculer la médiane de cette série de valeurs.`;
|
|
|
16
17
|
};
|
|
17
18
|
const getAnswer = (identifiers) => {
|
|
18
19
|
const { randomEffectives, randomValues } = identifiers;
|
|
19
|
-
|
|
20
|
-
const middleIndex = Math.floor(n / 2);
|
|
21
|
-
let median;
|
|
22
|
-
if (n % 2 === 0) {
|
|
23
|
-
median = (randomValues[middleIndex - 1] + randomValues[middleIndex]) / 2;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
median = randomValues[middleIndex];
|
|
27
|
-
}
|
|
28
|
-
const answer = (median + "").replace(".", ",");
|
|
29
|
-
return answer;
|
|
20
|
+
return median(randomValues, randomEffectives).frenchify();
|
|
30
21
|
};
|
|
31
22
|
const getMedianWithTable = () => {
|
|
32
23
|
const getRandomUniqueValues = (count, min, max) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"medianList.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/stats1var/medianList.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"medianList.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/stats1var/medianList.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EAYT,MAAM,sBAAsB,CAAC;AAE9B,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AA+DF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAYhD,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randint } from "../../../../math/utils/random/randint.js";
|
|
2
|
+
import { median } from "../../../../math/utils/stats/median.js";
|
|
2
3
|
import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercise.js";
|
|
3
4
|
import { getDistinctQuestions } from "../../../utils/getDistinctQuestions.js";
|
|
4
5
|
const getInstruction = (identifiers) => {
|
|
@@ -13,16 +14,7 @@ Calculer la médiane de cette liste de valeurs.`;
|
|
|
13
14
|
};
|
|
14
15
|
const getAnswer = (identifiers) => {
|
|
15
16
|
const { sortedValues } = identifiers;
|
|
16
|
-
|
|
17
|
-
let median;
|
|
18
|
-
if (sortedValues.length % 2 === 0) {
|
|
19
|
-
median = (sortedValues[middleIndex - 1] + sortedValues[middleIndex]) / 2;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
median = sortedValues[middleIndex];
|
|
23
|
-
}
|
|
24
|
-
const answer = (median + "").replace(".", ",");
|
|
25
|
-
return answer;
|
|
17
|
+
return median(sortedValues).frenchify();
|
|
26
18
|
};
|
|
27
19
|
const getMedianList = () => {
|
|
28
20
|
let randomValues = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quartilesList.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/stats1var/quartilesList.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quartilesList.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/stats1var/quartilesList.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,QAAQ,EAYT,MAAM,sBAAsB,CAAC;AAG9B,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAuEF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,WAAW,CAY/C,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randint } from "../../../../math/utils/random/randint.js";
|
|
2
|
+
import { firstQuartile, thirdQuartile, } from "../../../../math/utils/stats/quartiles.js";
|
|
2
3
|
import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercise.js";
|
|
3
4
|
import { getDistinctQuestions } from "../../../utils/getDistinctQuestions.js";
|
|
4
5
|
const getInstruction = ({ randomQuartile, randomValues, }) => {
|
|
@@ -16,17 +17,10 @@ Calculer le ${quartileToString} de cette série de valeurs.`;
|
|
|
16
17
|
};
|
|
17
18
|
const getAnswer = (identifiers) => {
|
|
18
19
|
const { randomValues, randomQuartile } = identifiers;
|
|
19
|
-
const firstQuartileIndex = Math.round(randomValues.length / 4 + 0.49);
|
|
20
|
-
const thirdQuartileIndex = Math.round((3 * randomValues.length) / 4 + 0.49);
|
|
21
|
-
const firstQuartile = randomValues[firstQuartileIndex - 1];
|
|
22
|
-
const thirdQuartile = randomValues[thirdQuartileIndex - 1];
|
|
23
|
-
let choosenQuartile;
|
|
24
20
|
if (randomQuartile === 0)
|
|
25
|
-
|
|
21
|
+
return firstQuartile(randomValues).frenchify();
|
|
26
22
|
else
|
|
27
|
-
|
|
28
|
-
const answer = choosenQuartile + "";
|
|
29
|
-
return answer;
|
|
23
|
+
return thirdQuartile(randomValues).frenchify();
|
|
30
24
|
};
|
|
31
25
|
const getQuartiles = () => {
|
|
32
26
|
let randomValues = [];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"median.d.ts","sourceRoot":"","sources":["../../../../src/math/utils/stats/median.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,iBAAkB,MAAM,EAAE,cAAc,MAAM,EAAE,WAgClE,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//! values must be sorted
|
|
2
|
+
export const median = (sortedValues, effectifs) => {
|
|
3
|
+
if (!sortedValues.length)
|
|
4
|
+
throw Error("Malformed data in median");
|
|
5
|
+
if (!effectifs?.length) {
|
|
6
|
+
const N = sortedValues.length;
|
|
7
|
+
if (N % 2 === 0) {
|
|
8
|
+
return (sortedValues[N / 2 - 1] + sortedValues[N / 2]) / 2;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return sortedValues[Math.floor(N / 2)];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const N = effectifs.reduce((acc, curr) => acc + curr, 0);
|
|
16
|
+
if (N % 2 === 0) {
|
|
17
|
+
let s = 0;
|
|
18
|
+
for (let i = 0; i < effectifs.length; i++) {
|
|
19
|
+
s += effectifs[i];
|
|
20
|
+
if (N / 2 < s) {
|
|
21
|
+
return sortedValues[i];
|
|
22
|
+
}
|
|
23
|
+
if (N / 2 === s)
|
|
24
|
+
return (sortedValues[i] + sortedValues[i + 1]) / 2;
|
|
25
|
+
}
|
|
26
|
+
return (sortedValues[N / 2 - 1] + sortedValues[N / 2]) / 2;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
let s = 0;
|
|
30
|
+
for (let i = 0; i < effectifs.length; i++) {
|
|
31
|
+
s += effectifs[i];
|
|
32
|
+
if (N / 2 <= s) {
|
|
33
|
+
return sortedValues[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return 0;
|
|
39
|
+
};
|
package/lib/playground.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,UAAU,YAMtB,CAAC"}
|
package/lib/playground.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Decimal } from "./math/numbers/decimals/decimal.js";
|
|
2
|
+
import { median } from "./math/utils/stats/median.js";
|
|
2
3
|
export const playground = () => {
|
|
3
4
|
const dec = new Decimal(0.0001);
|
|
4
5
|
const answer = dec
|
|
5
6
|
.toScientificNotation()
|
|
6
7
|
.toTex({ forceNoSimplification: true });
|
|
7
|
-
console.log(
|
|
8
|
+
console.log(median([1, 2, 3, 4], [1, 2, 10, 2]));
|
|
8
9
|
};
|