I have a problem link
Where I have only 3 requirements:
- Create a function that logs a message with whatever passed in arguements
- Chain mutiple methods on it.
- Give priority in execution of method chaining (e.g. here we need to give priority to sleepFirst, irrespective of its order.)
const LazyMan = (name, logFn)=>{
logFn(`Hi, I'm ${name}.`)
return []
}
Array.prototype.sleepFirst = function (time) {
console.log(`Wake up after ${time} seconds.`)
return this;
}
Array.prototype.eat = function (food){
console.log(`Eat ${food}`)
return this;
}
Array.prototype.sleep = function (second){
console.log(`Wake up after ${second} seconds.`)
return this;
}
LazyMan('Ashish', console.log).eat('apple').sleep(10).sleepFirst(20)
Current Output:
Hi, I’m Ashish.
Eat apple
Wake up after 10 seconds.
Wake up after 20 seconds.
Expected Output:
Wake up after 20 seconds.
Hi, I’m Ashish.
Eat apple
Wake up after 10 seconds.