Skip to content

Commit 0dc81a8

Browse files
authored
Shortened sign to sgn in most (not all) places
1 parent 3d865f3 commit 0dc81a8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Maths/Fibonacci.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const FibonacciRecursive = (number) => {
3232
case number:
3333
return list
3434
default:
35-
const sign = number < 0
35+
const sgn = number < 0
3636
list.push(
37-
sign ?
37+
sgn ?
3838
list.at(-2) - list.at(-1)
3939
:
4040
list.at(-1) + list.at(-2)
@@ -47,16 +47,16 @@ const FibonacciRecursive = (number) => {
4747
const dict = new Map()
4848

4949
const FibonacciRecursiveDP = (stairs) => {
50-
const sign = stairs < 0
51-
if (sign) stairs *= -1
50+
const sgn = stairs < 0
51+
if (sgn) stairs *= -1
5252

5353
if (stairs === 0) return 0
5454
if (stairs === 1) return 1
5555

5656
// Memoize stair count
5757
if (dict.has(stairs)) return dict.get(stairs)
5858

59-
const res = sign
59+
const res = sgn
6060
? FibonacciRecursiveDP(stairs - 2) - FibonacciRecursiveDP(stairs - 1)
6161
: FibonacciRecursiveDP(stairs - 1) + FibonacciRecursiveDP(stairs - 2)
6262

@@ -171,8 +171,8 @@ const FibonacciMatrixExpo = (n) => {
171171

172172
if (n === 0 || n === 0n) return n
173173

174-
const sign = n < 0
175-
if (sign) n = -n
174+
const sgn = n < 0
175+
if (sgn) n = -n
176176

177177
const isBigInt = typeof n === 'bigint'
178178
const ZERO = isBigInt ? 0n : 0
@@ -189,7 +189,7 @@ const FibonacciMatrixExpo = (n) => {
189189
[ZERO]
190190
]
191191
F = matrixMultiply(poweredA, F)
192-
return F[0][0] * (sign ? (-ONE) ** (n + ONE) : ONE)
192+
return F[0][0] * (sgn ? (-ONE) ** (n + ONE) : ONE)
193193
}
194194

195195
export { FibonacciDpWithoutRecursion }

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