Skip to content

Instantly share code, notes, and snippets.

@chernjie
Created June 21, 2022 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chernjie/bf2efd2af6b783a93a8508f908a7d9ad to your computer and use it in GitHub Desktop.
Save chernjie/bf2efd2af6b783a93a8508f908a7d9ad to your computer and use it in GitHub Desktop.
chive vanilla js practice
$$('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