IK
Interview Knowledge Book
Topics
Practice
Examples
Playground
RU
browser
Strategy pattern validation
Swap validation policy through a strategy function while the use case stays stable.
index.js
function createSignup(validatePassword) { return (password) => validatePassword(password); } const basic = createSignup((value) => value.length >= 8); const strict = createSignup((value) => value.length >= 12 && /\d/.test(value)); console.log('basic', basic('longpass')); console.log('strict', strict('longpass'));
Run
Stop
Reset