Skip to content

Commit 592cec4

Browse files
committed
chore: apply updated code style automatically
1 parent 60b4cff commit 592cec4

File tree

166 files changed

+1482
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+1482
-543
lines changed

Backtracking/KnightTour.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class OpenKnightTour {
1919
[i - 1, j + 2]
2020
]
2121

22-
return moves.filter(([y, x]) => y >= 0 && y < this.size && x >= 0 && x < this.size)
22+
return moves.filter(
23+
([y, x]) => y >= 0 && y < this.size && x >= 0 && x < this.size
24+
)
2325
}
2426

2527
isComplete() {

Backtracking/RatInAMaze.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222
* @throws TypeError When the given grid is invalid.
2323
*/
2424
function validateGrid(grid) {
25-
if (!Array.isArray(grid) || grid.length === 0) throw new TypeError('Grid must be a non-empty array')
25+
if (!Array.isArray(grid) || grid.length === 0)
26+
throw new TypeError('Grid must be a non-empty array')
2627

27-
const allRowsHaveCorrectLength = grid.every((row) => row.length === grid.length)
28+
const allRowsHaveCorrectLength = grid.every(
29+
(row) => row.length === grid.length
30+
)
2831
if (!allRowsHaveCorrectLength) throw new TypeError('Grid must be a square')
2932

3033
const allCellsHaveValidValues = grid.every((row) => {
3134
return row.every((cell) => cell === 0 || cell === 1)
3235
})
33-
if (!allCellsHaveValidValues) throw new TypeError('Grid must only contain 0s and 1s')
36+
if (!allCellsHaveValidValues)
37+
throw new TypeError('Grid must only contain 0s and 1s')
3438
}
3539

3640
function isSafe(grid, x, y) {

Backtracking/Sudoku.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ class Sudoku {
6666
if (i % 3 === 0 && i !== 0) {
6767
output('- - - - - - - - - - - -')
6868
}
69-
output(...this.getSection(i, [0, 3]), ' | ', ...this.getSection(i, [3, 6]), ' | ', ...this.getSection(i, [6, 9]))
69+
output(
70+
...this.getSection(i, [0, 3]),
71+
' | ',
72+
...this.getSection(i, [3, 6]),
73+
' | ',
74+
...this.getSection(i, [6, 9])
75+
)
7076
}
7177
}
7278
}

Backtracking/SumOfSubset.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ const sumOfSubset = (set, subset, setindex, sum, targetSum) => {
4545
const nextSum = sum + num
4646

4747
// Call recursively the sumOfSubset for the nextSubset
48-
const subsetResult = sumOfSubset(set, nextSubset, nextSetIndex, nextSum, targetSum)
48+
const subsetResult = sumOfSubset(
49+
set,
50+
nextSubset,
51+
nextSetIndex,
52+
nextSum,
53+
targetSum
54+
)
4955

5056
// Concat the recursive result with current result array
5157
results = [...results, ...subsetResult]
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { generateParentheses } from '../generateParentheses'
22

33
test('generate all valid parentheses of input 3', () => {
4-
expect(generateParentheses(3)).toStrictEqual(['((()))', '(()())', '(())()', '()(())', '()()()'])
4+
expect(generateParentheses(3)).toStrictEqual([
5+
'((()))',
6+
'(()())',
7+
'(())()',
8+
'()(())',
9+
'()()()'
10+
])
511
})

Cellular-Automata/ConwaysGameOfLife.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ export function newGeneration(cells) {
2020
let neighbourCount = 0
2121
if (i > 0 && j > 0) neighbourCount += cells[i - 1][j - 1]
2222
if (i > 0) neighbourCount += cells[i - 1][j]
23-
if (i > 0 && j < cells[i].length - 1) neighbourCount += cells[i - 1][j + 1]
23+
if (i > 0 && j < cells[i].length - 1)
24+
neighbourCount += cells[i - 1][j + 1]
2425
if (j > 0) neighbourCount += cells[i][j - 1]
2526
if (j < cells[i].length - 1) neighbourCount += cells[i][j + 1]
2627
if (i < cells.length - 1 && j > 0) neighbourCount += cells[i + 1][j - 1]
2728
if (i < cells.length - 1) neighbourCount += cells[i + 1][j]
28-
if (i < cells.length - 1 && j < cells[i].length - 1) neighbourCount += cells[i + 1][j + 1]
29+
if (i < cells.length - 1 && j < cells[i].length - 1)
30+
neighbourCount += cells[i + 1][j + 1]
2931

3032
// Decide whether the cell is alive or dead
3133
const alive = cells[i][j] === 1
3234

33-
const cellIsAlive = (alive && neighbourCount >= 2 && neighbourCount <= 3) || (!alive && neighbourCount === 3)
35+
const cellIsAlive =
36+
(alive && neighbourCount >= 2 && neighbourCount <= 3) ||
37+
(!alive && neighbourCount === 3)
3438

3539
nextGenerationRow.push(cellIsAlive ? 1 : 0)
3640
}

Cellular-Automata/Elementary.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,19 @@ export function getNextElementaryGeneration(generation, rule) {
7070
const MAX_RULE = 255
7171

7272
if (!Number.isInteger(rule)) {
73-
throw new Error(`Rule must be an integer between the values 0 and 255 (got ${rule})`)
73+
throw new Error(
74+
`Rule must be an integer between the values 0 and 255 (got ${rule})`
75+
)
7476
}
7577
if (rule < MIN_RULE || rule > MAX_RULE) {
76-
throw new RangeError(`Rule must be an integer between the values 0 and 255 (got ${rule})`)
78+
throw new RangeError(
79+
`Rule must be an integer between the values 0 and 255 (got ${rule})`
80+
)
7781
}
7882

79-
const binaryRule = rule.toString(2).padStart(NUM_ELEMENTARY_NEIGHBORHOOD_STATES, '0')
83+
const binaryRule = rule
84+
.toString(2)
85+
.padStart(NUM_ELEMENTARY_NEIGHBORHOOD_STATES, '0')
8086
const ruleData = binaryRule.split('').map((bit) => Number.parseInt(bit)) // note that ruleData[0] represents "all alive" while ruleData[7] represents "all dead"
8187
const output = new Array(generation.length)
8288
const LEFT_DEAD = 4 // 100 in binary

Cellular-Automata/test/Elementary.test.js

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,129 +3,137 @@ import { getNextElementaryGeneration } from '../Elementary'
33
describe('Elementary Cellular Automata', () => {
44
describe('Rule Errors', () => {
55
it('Correct', () => {
6-
expect(() => getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 128)).not.toThrow()
6+
expect(() =>
7+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 128)
8+
).not.toThrow()
79
})
810

911
it('Less than 0', () => {
10-
expect(() => getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], -1)).toThrow()
12+
expect(() =>
13+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], -1)
14+
).toThrow()
1115
})
1216

1317
it('Greater than 255', () => {
14-
expect(() => getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 256)).toThrow()
18+
expect(() =>
19+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 256)
20+
).toThrow()
1521
})
1622

1723
it('Decimal', () => {
18-
expect(() => getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 100.4)).toThrow()
24+
expect(() =>
25+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 100.4)
26+
).toThrow()
1927
})
2028
})
2129

2230
describe('Rule 54 Iterations', () => {
2331
it('Generation 1', () => {
24-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 54)).toEqual([
25-
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0
26-
])
32+
expect(
33+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 54)
34+
).toEqual([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0])
2735
})
2836
it('Generation 2', () => {
29-
expect(getNextElementaryGeneration([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], 54)).toEqual([
30-
0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0
31-
])
37+
expect(
38+
getNextElementaryGeneration([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], 54)
39+
).toEqual([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0])
3240
})
3341
it('Generation 3', () => {
34-
expect(getNextElementaryGeneration([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], 54)).toEqual([
35-
0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0
36-
])
42+
expect(
43+
getNextElementaryGeneration([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], 54)
44+
).toEqual([0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0])
3745
})
3846
it('Generation 4', () => {
39-
expect(getNextElementaryGeneration([0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0], 54)).toEqual([
40-
0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0
41-
])
47+
expect(
48+
getNextElementaryGeneration([0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0], 54)
49+
).toEqual([0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0])
4250
})
4351
})
4452

4553
describe('Rule 222 Iterations', () => {
4654
it('Generation 1', () => {
47-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 222)).toEqual([
48-
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0
49-
])
55+
expect(
56+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 222)
57+
).toEqual([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0])
5058
})
5159
it('Generation 2', () => {
52-
expect(getNextElementaryGeneration([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], 222)).toEqual([
53-
0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0
54-
])
60+
expect(
61+
getNextElementaryGeneration([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], 222)
62+
).toEqual([0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0])
5563
})
5664
it('Generation 3', () => {
57-
expect(getNextElementaryGeneration([0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], 222)).toEqual([
58-
0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0
59-
])
65+
expect(
66+
getNextElementaryGeneration([0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], 222)
67+
).toEqual([0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0])
6068
})
6169
it('Generation 4', () => {
62-
expect(getNextElementaryGeneration([0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0], 222)).toEqual([
63-
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
64-
])
70+
expect(
71+
getNextElementaryGeneration([0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0], 222)
72+
).toEqual([0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0])
6573
})
6674
})
6775

6876
describe('Rule 60 Iterations', () => {
6977
it('Generation 1', () => {
70-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 60)).toEqual([
71-
0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0
72-
])
78+
expect(
79+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 60)
80+
).toEqual([0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0])
7381
})
7482
it('Generation 2', () => {
75-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0], 60)).toEqual([
76-
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0
77-
])
83+
expect(
84+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0], 60)
85+
).toEqual([0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0])
7886
})
7987
it('Generation 3', () => {
80-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], 60)).toEqual([
81-
0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0
82-
])
88+
expect(
89+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], 60)
90+
).toEqual([0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0])
8391
})
8492
it('Generation 4', () => {
85-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 60)).toEqual([
86-
0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0
87-
])
93+
expect(
94+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 60)
95+
).toEqual([0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0])
8896
})
8997
})
9098

9199
describe('Rule 90 Iterations', () => {
92100
it('Generation 1', () => {
93-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 90)).toEqual([
94-
0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0
95-
])
101+
expect(
102+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 90)
103+
).toEqual([0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0])
96104
})
97105
it('Generation 2', () => {
98-
expect(getNextElementaryGeneration([0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0], 90)).toEqual([
99-
0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0
100-
])
106+
expect(
107+
getNextElementaryGeneration([0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0], 90)
108+
).toEqual([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0])
101109
})
102110
it('Generation 3', () => {
103-
expect(getNextElementaryGeneration([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], 90)).toEqual([
104-
0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0
105-
])
111+
expect(
112+
getNextElementaryGeneration([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], 90)
113+
).toEqual([0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0])
106114
})
107115
it('Generation 4', () => {
108-
expect(getNextElementaryGeneration([0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0], 90)).toEqual([
109-
0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0
110-
])
116+
expect(
117+
getNextElementaryGeneration([0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0], 90)
118+
).toEqual([0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0])
111119
})
112120
})
113121

114122
describe('Rule 30 Iterations', () => {
115123
it('Generation 1', () => {
116-
expect(getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 30)).toEqual([
117-
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0
118-
])
124+
expect(
125+
getNextElementaryGeneration([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 30)
126+
).toEqual([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0])
119127
})
120128
it('Generation 2', () => {
121-
expect(getNextElementaryGeneration([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], 30)).toEqual([
122-
0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0
123-
])
129+
expect(
130+
getNextElementaryGeneration([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], 30)
131+
).toEqual([0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0])
124132
})
125133
it('Generation 3', () => {
126-
expect(getNextElementaryGeneration([0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0], 30)).toEqual([
127-
0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0
128-
])
134+
expect(
135+
getNextElementaryGeneration([0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0], 30)
136+
).toEqual([0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0])
129137
})
130138
})
131139
})

Ciphers/CaesarCipher.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ const caesarCipher = (str, rotation) => {
1111
throw new TypeError('Arguments are invalid')
1212
}
1313

14-
const alphabets = new Array(26).fill().map((_, index) => String.fromCharCode(97 + index)) // generate all lower alphabets array a-z
14+
const alphabets = new Array(26)
15+
.fill()
16+
.map((_, index) => String.fromCharCode(97 + index)) // generate all lower alphabets array a-z
1517

16-
const cipherMap = alphabets.reduce((map, char, index) => map.set(char, alphabets[(rotation + index) % 26]), new Map())
18+
const cipherMap = alphabets.reduce(
19+
(map, char, index) => map.set(char, alphabets[(rotation + index) % 26]),
20+
new Map()
21+
)
1722

1823
return str.replace(/[a-z]/gi, (char) => {
1924
if (/[A-Z]/.test(char)) {

Ciphers/KeywordShiftedAlphabet.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ function translate(sourceAlphabet, targetAlphabet, message) {
6969
return message.split('').reduce((encryptedMessage, char) => {
7070
const isUpperCase = char === char.toUpperCase()
7171
const encryptedCharIndex = sourceAlphabet.indexOf(char.toLowerCase())
72-
const encryptedChar = encryptedCharIndex !== -1 ? targetAlphabet[encryptedCharIndex] : char
73-
encryptedMessage += isUpperCase ? encryptedChar.toUpperCase() : encryptedChar
72+
const encryptedChar =
73+
encryptedCharIndex !== -1 ? targetAlphabet[encryptedCharIndex] : char
74+
encryptedMessage += isUpperCase
75+
? encryptedChar.toUpperCase()
76+
: encryptedChar
7477
return encryptedMessage
7578
}, '')
7679
}
@@ -87,12 +90,20 @@ function checkInputs(keyword, message) {
8790

8891
function encrypt(keyword, message) {
8992
checkInputs(keyword, message)
90-
return translate(alphabet, getEncryptedAlphabet(keyword.toLowerCase()), message)
93+
return translate(
94+
alphabet,
95+
getEncryptedAlphabet(keyword.toLowerCase()),
96+
message
97+
)
9198
}
9299

93100
function decrypt(keyword, message) {
94101
checkInputs(keyword, message)
95-
return translate(getEncryptedAlphabet(keyword.toLowerCase()), alphabet, message)
102+
return translate(
103+
getEncryptedAlphabet(keyword.toLowerCase()),
104+
alphabet,
105+
message
106+
)
96107
}
97108

98109
export { encrypt, decrypt }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy