mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
Fix/code smells (#1338)
* ♻️ refactor: improving and fixing some code * Updated Documentation in README.md * ♻️ refactor: improving isLeapYear * 🐛 chore: back changes * 🐛 fix: using reduce instead forEach * 🐛 fix: using reduce instead forEach * 🐛 fix: removing duplicated code * 🐛 chore: removing .js --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@@ -29,11 +29,12 @@ export function newGeneration (cells) {
|
||||
|
||||
// Decide whether the cell is alive or dead
|
||||
const alive = cells[i][j] === 1
|
||||
if ((alive && neighbourCount >= 2 && neighbourCount <= 3) || (!alive && neighbourCount === 3)) {
|
||||
nextGenerationRow.push(1)
|
||||
} else {
|
||||
nextGenerationRow.push(0)
|
||||
}
|
||||
|
||||
const cellIsAlive =
|
||||
(alive && neighbourCount >= 2 && neighbourCount <= 3) ||
|
||||
(!alive && neighbourCount === 3)
|
||||
|
||||
nextGenerationRow.push(cellIsAlive ? 1 : 0)
|
||||
}
|
||||
nextGeneration.push(nextGenerationRow)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user