feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
export abstract class BaseNode {
|
||||
id: string;
|
||||
type: string;
|
||||
inputs: Map<string, any>;
|
||||
outputs: Map<string, any>;
|
||||
|
||||
constructor(id: string, type: string) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.inputs = new Map();
|
||||
this.outputs = new Map();
|
||||
}
|
||||
|
||||
abstract process(): void;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BaseNode } from './baseNode';
|
||||
|
||||
export class ReflectionNode extends BaseNode {
|
||||
constructor(id: string) {
|
||||
super(id, 'reflection');
|
||||
}
|
||||
|
||||
process(): void {
|
||||
// Copy all inputs to outputs with the same keys
|
||||
this.inputs.forEach((value, key) => {
|
||||
this.outputs.set(key, value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { BaseNode } from './baseNode';
|
||||
|
||||
export type RewriteFunction = (value: any) => any;
|
||||
|
||||
export class RewriteNode extends BaseNode {
|
||||
private func: RewriteFunction;
|
||||
|
||||
constructor(id: string, func: RewriteFunction) {
|
||||
super(id, 'rewrite');
|
||||
this.func = func;
|
||||
}
|
||||
|
||||
process(): void {
|
||||
this.inputs.forEach((value, key) => {
|
||||
const newValue = this.func(value);
|
||||
this.outputs.set(key, newValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user