Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Add fibonacci example
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Mar 8, 2017
1 parent 5487bac commit 1520ed2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Empty file added examples/fibonacci/README.md
Empty file.
32 changes: 32 additions & 0 deletions examples/fibonacci/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

const {whilst} = require('async')
const minDelay = require('min-delay')(500)

function fibonacci (num) {
if (num <= 1) return 1
return fibonacci(num - 1) + fibonacci(num - 2)
}

module.exports = function (opts, done) {
const {worker} = opts
const condition = () => true

function log () {
const args = [`#${worker}`].concat(...arguments)
console.log(...args)
}

whilst(
condition,
function (next) {
const fn = () => {
const result = fibonacci(worker)
log(`fibonacci result is ${result}`)
next()
}
minDelay(fn)
},
process.exit
)
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
"worker-farm": "~1.3.1"
},
"devDependencies": {
"async": "~2.1.5",
"coveralls": "latest",
"git-dirty": "latest",
"min-delay": "~1.0.1",
"mocha": "latest",
"nyc": "latest",
"should": "latest",
Expand Down

0 comments on commit 1520ed2

Please # to comment.