feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'

This commit is contained in:
2026-07-01 11:19:02 +03:00
parent 045dba9aef
commit cfe5d77a10
10 changed files with 309 additions and 94 deletions
+12
View File
@@ -0,0 +1,12 @@
class BaseNode {
constructor(name, graph) {
this.name = name;
this.graph = graph;
}
evaluate(input) {
throw new Error('evaluate() must be implemented by subclass');
}
}
module.exports = BaseNode;
+19
View File
@@ -0,0 +1,19 @@
export default class ReflectionNode {
/**
* Creates a new ReflectionNode.
* @param {string} id - Unique identifier for the node.
*/
constructor(id) {
this.id = id;
this.type = 'reflection';
}
/**
* Processes the input and returns it unchanged.
* @param {*} input - The input value from the preceding node(s).
* @returns {*} The same input value.
*/
process(input) {
return input;
}
}
+21
View File
@@ -0,0 +1,21 @@
export default class RewriteNode {
/**
* Creates a new RewriteNode.
* @param {string} id - Unique identifier for the node.
* @param {function} transform - Function that transforms the input.
*/
constructor(id, transform) {
this.id = id;
this.type = 'rewrite';
this.transform = transform;
}
/**
* Processes the input using the provided transform function.
* @param {*} input - The input value from the preceding node(s).
* @returns {*} The transformed output.
*/
process(input) {
return this.transform(input);
}
}