diff --git a/Exercises/2-compose.js b/Exercises/2-compose.js index 368e521..9530138 100644 --- a/Exercises/2-compose.js +++ b/Exercises/2-compose.js @@ -1,5 +1,22 @@ 'use strict'; -const compose = (...fns) => x => null; +const compose = (...fns) => { + let error = null; + try { + for (const fn of fns) { + if (!(fn instanceof Function)) throw new Error('Type of argument should be a function.'); + } + } catch (e) { + error = e; + } + const composed = x => { + if (error) return undefined; + return fns.reduceRight((v, f) => f(v), x); + } + composed.on = (eventName, callback) => { + if (eventName === 'error' && error) callback(error); + } + return composed; +} module.exports = { compose }; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy