Created
April 24, 2015 14:12
-
-
Save grekko/8c1b2482f5c20ed888cf to your computer and use it in GitHub Desktop.
One-Dimensional Game of Life in one sane line of ES6 JS
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
describe('Game of life', function() { | |
it('should evolve exist', function() { | |
assert.equal(typeof e, 'function'); | |
}); | |
it('should evolve return same length list', function() { | |
var board = [0, 0, 0, 0, 0]; | |
assert.equal(e(board).length, board.length); | |
}); | |
it('should evolve the list', function() { | |
var board = [1, 1, 1]; // expected: [0, 1, 0] | |
assert.deepEqual(e(board), [0, 1, 0]); | |
}); | |
it('should evolve the list', function() { | |
var board = [1, 1, 1, 1]; // expected: [0, 1,1, 0] | |
assert.deepEqual(e(board), [0, 1, 1, 0]); | |
}); | |
it('should evolve the list', function() { | |
var board = [1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1]; | |
// expected: [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0] | |
assert.deepEqual(e(board), [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0]); | |
}); | |
}); | |
//var e = (b) => b.map((_, i, b) => b[i-1] && b[i+1] ? 1 : 0 ); | |
//var e = (b) => b.map((_, i, b) => b[i-1] && b[i+1] ); | |
var e = (b) => b.map((_, i, b) => +(!!(b[i-1] && b[i+1]))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment