Skip to content

Instantly share code, notes, and snippets.

@jaysoo
Created June 23, 2011 19:36
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 jaysoo/1043431 to your computer and use it in GitHub Desktop.
Save jaysoo/1043431 to your computer and use it in GitHub Desktop.
JavaScript exercise: wibblefish
<!doctype html>
<title>wibblefish</title>
<pre id="results"></pre>
<script>
window.functions = [
function(i) { return i%3 == 0 ? 'wibble' : '' },
function(i) { return i%5 == 0 ? 'fish' : '' }
]
window.wibblefish = function(n) {
var arr = []
for (var i = 1; i <= n; i++) {
var result = ''
for (var j = 0, fn; fn = window.functions[j]; j++) {
result += fn(i)
}
result = result || i
arr.push(result)
}
return arr.join('\n')
}
document.getElementById('results').innerHTML = wibblefish(100)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment