EasyTypeScript

Prototype

TypeScriptDesign PatternsCreationalPrototype

Create new objects by cloning an existing instance rather than instantiating from scratch — the clone must be fully independent: mutating it must never affect the original.

Implement `ShapePrototype.clone()`, returning a new, independent ShapePrototype with the same type/color.

solve(type, color, newColor) clones a shape, changes the clone's color to newColor, and returns both { original, clone } — proving the original is untouched.

Sample tests

Test #1Clone color diverges from original
Input: ["circle","red","blue"]
Output: {"clone":{"type":"circle","color":"blue"},"original":{"type":"circle","color":"red"}}
Test #2Same color is still independent copies
Input: ["square","green","green"]
Output: {"clone":{"type":"square","color":"green"},"original":{"type":"square","color":"green"}}
Test #3Different shape type
Input: ["triangle","black","white"]
Output: {"clone":{"type":"triangle","color":"white"},"original":{"type":"triangle","color":"black"}}