Skip to content

Instantly share code, notes, and snippets.

@IrakliJani
Last active August 29, 2015 14:14
Show Gist options
  • Save IrakliJani/ea85c391615a7a9cb6ec to your computer and use it in GitHub Desktop.
Save IrakliJani/ea85c391615a7a9cb6ec to your computer and use it in GitHub Desktop.
assert = require 'assert'
module.exports = fn = (data) ->
return [data] unless data instanceof Array
a = []
a = a.concat(fn(elem)) for elem in data
a
assert.deepEqual(fn( 3 ), [3] )
assert.deepEqual(fn( { a: 1, b: "hi", c: /xyz/ } ), [ { a: 1, b: "hi", c: /xyz/ } ] )
assert.deepEqual(fn( [ 1, 2, 5 ] ), [ 1, 2, 5 ] )
assert.deepEqual(fn( [ 1, [[[[[ 2 ]]]]], [[[[ 5 ]]]] ] ), [ 1, 2, 5 ] )
assert.deepEqual(fn( [ [ 1, [ [ [ 2, 3 ], 4, 5 ], 6 ] ] ] ), [ 1, 2, 3, 4, 5, 6 ] )
assert.deepEqual(fn( [ undefined, [ null ] ] ), [ undefined, null ] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment