mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00
feat: Test running overhaul, switch to Prettier & reformat everything (#1407)
* chore: Switch to Node 20 + Vitest * chore: migrate to vitest mock functions * chore: code style (switch to prettier) * test: re-enable long-running test Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime! see #1193 * chore: code style * chore: fix failing tests * Updated Documentation in README.md * Update contribution guidelines to state usage of Prettier * fix: set prettier printWidth back to 80 * chore: apply updated code style automatically * fix: set prettier line endings to lf again * chore: apply updated code style automatically --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
@ -64,20 +64,26 @@
|
||||
* @param {number} rule The current rule of the Elementary Cellular Automata simulation. Must be an integer between 0 and 255 inclusive
|
||||
* @returns {(0 | 1)[]} The next generation according to the inputted rule
|
||||
*/
|
||||
export function getNextElementaryGeneration (generation, rule) {
|
||||
export function getNextElementaryGeneration(generation, rule) {
|
||||
const NUM_ELEMENTARY_NEIGHBORHOOD_STATES = 8
|
||||
const MIN_RULE = 0
|
||||
const MAX_RULE = 255
|
||||
|
||||
if (!Number.isInteger(rule)) {
|
||||
throw new Error(`Rule must be an integer between the values 0 and 255 (got ${rule})`)
|
||||
throw new Error(
|
||||
`Rule must be an integer between the values 0 and 255 (got ${rule})`
|
||||
)
|
||||
}
|
||||
if (rule < MIN_RULE || rule > MAX_RULE) {
|
||||
throw new RangeError(`Rule must be an integer between the values 0 and 255 (got ${rule})`)
|
||||
throw new RangeError(
|
||||
`Rule must be an integer between the values 0 and 255 (got ${rule})`
|
||||
)
|
||||
}
|
||||
|
||||
const binaryRule = rule.toString(2).padStart(NUM_ELEMENTARY_NEIGHBORHOOD_STATES, '0')
|
||||
const ruleData = binaryRule.split('').map(bit => Number.parseInt(bit)) // note that ruleData[0] represents "all alive" while ruleData[7] represents "all dead"
|
||||
const binaryRule = rule
|
||||
.toString(2)
|
||||
.padStart(NUM_ELEMENTARY_NEIGHBORHOOD_STATES, '0')
|
||||
const ruleData = binaryRule.split('').map((bit) => Number.parseInt(bit)) // note that ruleData[0] represents "all alive" while ruleData[7] represents "all dead"
|
||||
const output = new Array(generation.length)
|
||||
const LEFT_DEAD = 4 // 100 in binary
|
||||
const MIDDLE_DEAD = 2 // 010 in binary
|
||||
|
Reference in New Issue
Block a user