ects-kornii-chervonenko 1.0.0
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/index.js +31 -0
- package/isInRange.js +16 -0
- package/package.json +21 -0
- package/ranges.js +16 -0
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isInRange = require('./isInRange.js');
|
|
4
|
+
const ranges = require('./ranges.js');
|
|
5
|
+
|
|
6
|
+
const RangeErrorMsg = `Should be a number in range from ${ranges.min} to ${ranges.max}`;
|
|
7
|
+
|
|
8
|
+
class ECTS {
|
|
9
|
+
#ects;
|
|
10
|
+
|
|
11
|
+
constructor(score) {
|
|
12
|
+
if (!isInRange(score, [ranges.min, ranges.max])) throw new RangeError(RangeErrorMsg);
|
|
13
|
+
|
|
14
|
+
const found = ranges.allRanges.find((range) => isInRange(score, [range.min, range.max]));
|
|
15
|
+
if (!found) throw new RangeError(RangeErrorMsg);
|
|
16
|
+
this.#ects = found.grade;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ectsFromScore() {
|
|
20
|
+
return this.#ects;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = ECTS;
|
|
25
|
+
|
|
26
|
+
// const ectsScores = [91, 80, 70, 60, 45, 30];
|
|
27
|
+
// ectsScores.forEach((score) => {
|
|
28
|
+
// const ectsCalculator = new ECTS(score);
|
|
29
|
+
// const ectsResult = ectsCalculator.ectsFromScore();
|
|
30
|
+
// console.log(`Score: ${score}, ECTS Grade: ${ectsResult}`);
|
|
31
|
+
// });
|
package/isInRange.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function isInRange(value, range) {
|
|
4
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) return false;
|
|
5
|
+
const min = Math.min(...range);
|
|
6
|
+
const max = Math.max(...range);
|
|
7
|
+
return min <= value && value <= max;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = isInRange;
|
|
11
|
+
|
|
12
|
+
// console.log(isInRange(50, [0, 100]) === true);
|
|
13
|
+
// console.log(isInRange(-50, [0, -100]) === true);
|
|
14
|
+
// console.log(isInRange(-50, [-100, 0]) === true);
|
|
15
|
+
// console.log(isInRange('50', [0, 100]) === false);
|
|
16
|
+
// console.log(isInRange(-50, [0, 100]) === false);
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ects-kornii-chervonenko",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "Kornii Chervonenko",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"type": "commonjs",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/KorneyChervonenko/ects-kornii-chervonenko.git"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/KorneyChervonenko/ects-kornii-chervonenko.git",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/KorneyChervonenko/ects-kornii-chervonenko.git"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/ranges.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const allRanges = [
|
|
4
|
+
{ min: 0, max: 59, grade: 'F' },
|
|
5
|
+
{ min: 60, max: 64, grade: 'E' },
|
|
6
|
+
{ min: 65, max: 73, grade: 'D' },
|
|
7
|
+
{ min: 74, max: 81, grade: 'C' },
|
|
8
|
+
{ min: 82, max: 89, grade: 'B' },
|
|
9
|
+
{ min: 90, max: 100, grade: 'A' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const values = allRanges.flatMap((range) => [range.min, range.max]);
|
|
13
|
+
const min = Math.min(...values);
|
|
14
|
+
const max = Math.max(...values);
|
|
15
|
+
|
|
16
|
+
module.exports = { allRanges, min, max };
|