feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user