Created
June 21, 2022 00:52
-
-
Save chernjie/bf2efd2af6b783a93a8508f908a7d9ad to your computer and use it in GitHub Desktop.
chive vanilla js practice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$$('figure img') | |
.map(el => el.src) | |
.reverse() | |
.reduce((last, next) => { | |
return () => { | |
setTimeout(() => { | |
console.log('<img src="'+ next +'" />') | |
last() | |
}, 1000) | |
} | |
}, ()=>{ console.log('finished') })() | |
$$('figure img') | |
.map(el => el.src) | |
.map(url => { | |
return next => { | |
setTimeout(() => { | |
console.log('<img src="'+ url +'" />') | |
next() | |
}, 1000) | |
} | |
}) | |
.reverse() | |
.reduce( | |
(last, next) => () => next(last), | |
() => console.log('finished') | |
)() | |
$$('figure img') | |
.map(el => el.src) | |
.map(url => () => !console.log('<img src="'+ url +'" />')) | |
.map(fn => next => fn() && next()) | |
.reverse() | |
.reduce( | |
(last, next) => (timeout = 1000) => setTimeout(() => next(last), timeout), | |
() => console.log('finished') | |
)(0) | |
// Not working | |
Array.prototype.waterfall = (callback = () => console.log('finished')) => { | |
this.reverse() | |
this.reduce( | |
(prev, next) => () => next(prev), | |
callback | |
)() | |
this.reverse() | |
} | |
// Not working | |
Array.prototype.queueTimeout = (callback = () => console.log('finished'), timeout = 1000) => { | |
this | |
.map(fn => next => fn() && next()) | |
.reverse() | |
.reduce( | |
(prev, next) => (t = timeout) => setTimeout(() => next(prev), t), | |
callback | |
)(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment