Question: Javascript: Your function should receive an object as its only argument and return an object with the same properties, but with type validation added. Types
Javascript: Your function should receive an object as its only argument and return an object with the same properties, but with type validation added. Types
should be validated when:
the function creates the object;
someone updates a property;
someone adds a property.
The type validation should always be based on the last part of the property name. For example, the ageint property should always be an integer
and throw an error when set to something else.
Here are possible types:
string: for example, "string type"
int: and are both integers
float: for example,
number: any int or float
bool: for example, true
Assumptions
Types are optional and validation should be skipped if the type isn't specified.
always precedes the type name.
Hints
JavaScript Proxy might be useful.
Your solution will be evaluated based on its correctness; performance and coding style will not be assessed.
Do not edit the default export.
Available toolspackages
Node.js
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
