-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
ea4c84b
commit 8e6dda1
Showing
29 changed files
with
1,403 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @file Fixtures - digitize | ||
* @module fixtures/digitize | ||
* @see https://codewars.com/kata/5583090cbe83f4fd8c000051 | ||
*/ | ||
|
||
/** | ||
* Given a random non-negative number, `n`, the function returns an array with | ||
* the digits of `n` in reverse. | ||
* | ||
* @example | ||
* digitize(0) // [0] | ||
* @example | ||
* digitize(348597) // [7, 9, 5, 8, 4, 3] | ||
* | ||
* @param {number} n - Positive integer to reverse | ||
* @return {number[]} Digits of `n` in reverse | ||
*/ | ||
const digitize = (n: number): number[] => { | ||
if (n <= 9) return [n] | ||
|
||
/** | ||
* Digits of {@linkcode n} reversed. | ||
* | ||
* @const {number[]} digits | ||
*/ | ||
const digits: number[] = [] | ||
|
||
// iterate through digits starting from rightmost digit | ||
while (n > 0) digits.push(n % 10 | 0) && (n = n / 10 | 0) | ||
|
||
return digits | ||
} | ||
|
||
export default digitize |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
/** | ||
* @file Fixtures - postorder | ||
* @module fixtures/postorder | ||
*/ | ||
|
||
import type { VisitedType } from '#tests/types' | ||
import type { EmptyArray } from '@flex-development/tutils' | ||
|
||
/** | ||
* Object containing node types visited during postorder traversal. | ||
*/ | ||
type Postorder = { | ||
/** | ||
* Ancestor node types visited during postorder traversal. | ||
* | ||
* @see {@linkcode VisitedType} | ||
*/ | ||
ancestors: [...VisitedType[][], EmptyArray] | ||
|
||
/** | ||
* Parent node types visited during postorder traversal. | ||
*/ | ||
parents: [...VisitedType[], undefined] | ||
|
||
/** | ||
* All node types visited during postorder traversal. | ||
* | ||
* @see {@linkcode VisitedType} | ||
*/ | ||
types: [...Exclude<VisitedType, 'root'>[], 'root'] | ||
|
||
/** | ||
* All node types visited during reverse postorder traversal. | ||
* | ||
* @see {@linkcode VisitedType} | ||
*/ | ||
typesReversed: [...Exclude<VisitedType, 'root'>[], 'root'] | ||
} | ||
|
||
/** | ||
* All node types visited during postorder traversal. | ||
* | ||
* @const {Postorder['types']} types | ||
*/ | ||
const types: Postorder['types'] = [ | ||
'text', | ||
'blockTag', | ||
'text', | ||
'blockTag', | ||
'text', | ||
'blockTag', | ||
'comment', | ||
'text', // siblings skipped | ||
'inlineCode', | ||
'text', | ||
'inlineCode', | ||
'text', | ||
'paragraph', | ||
'description', | ||
'code', | ||
'blockTag', | ||
'code', | ||
'blockTag', | ||
'typeExpression', | ||
'text', | ||
'blockTag', | ||
'typeExpression', | ||
'text', | ||
'inlineCode', | ||
'text', | ||
'blockTag', | ||
'comment', | ||
'text', | ||
'inlineTag', | ||
'text', | ||
'paragraph', | ||
'description', | ||
'typeExpression', | ||
'text', | ||
'blockTag', | ||
'comment', | ||
'root' | ||
] | ||
|
||
/** | ||
* All node types visited during reverse postorder traversal. | ||
* | ||
* @const {Postorder['typesReversed']} typesReversed | ||
*/ | ||
const typesReversed: Postorder['typesReversed'] = [ | ||
'text', | ||
'typeExpression', | ||
'blockTag', | ||
'text', | ||
'inlineTag', | ||
'text', | ||
'paragraph', | ||
'description', | ||
'comment', | ||
'text', | ||
'inlineCode', | ||
'text', | ||
'typeExpression', | ||
'blockTag', | ||
'text', | ||
'typeExpression', | ||
'blockTag', | ||
'code', | ||
'blockTag', | ||
'code', | ||
'blockTag', | ||
'text', | ||
'inlineCode', | ||
'text', | ||
'inlineCode', | ||
'text', | ||
'paragraph', | ||
'description', | ||
'comment', | ||
'text', | ||
'blockTag', | ||
'text', | ||
'blockTag', | ||
'text', | ||
'blockTag', | ||
'comment', | ||
'root' | ||
] | ||
|
||
/** | ||
* Parent node types visited during postorder traversal. | ||
* | ||
* @const {Postorder['parents']} parents | ||
*/ | ||
const parents: Postorder['parents'] = [ | ||
'blockTag', | ||
'comment', | ||
'blockTag', | ||
'comment', | ||
'blockTag', | ||
'comment', | ||
'root', | ||
'paragraph', | ||
'paragraph', | ||
'paragraph', | ||
'paragraph', | ||
'paragraph', | ||
'description', | ||
'comment', | ||
'blockTag', | ||
'comment', | ||
'blockTag', | ||
'comment', | ||
'blockTag', | ||
'blockTag', | ||
'comment', | ||
'blockTag', | ||
'blockTag', | ||
'blockTag', | ||
'blockTag', | ||
'comment', | ||
'root', | ||
'paragraph', | ||
'paragraph', | ||
'paragraph', | ||
'description', | ||
'comment', | ||
'blockTag', | ||
'blockTag', | ||
'comment', | ||
'root', | ||
undefined | ||
] | ||
|
||
/** | ||
* Ancestor node types visited during postorder traversal. | ||
* | ||
* @const {Postorder['ancestors']} ancestors | ||
*/ | ||
const ancestors: Postorder['ancestors'] = [ | ||
['root', 'comment'], | ||
['root'], | ||
['root', 'comment'], | ||
['root'], | ||
['root', 'comment'], | ||
['root'], | ||
[], | ||
['root', 'comment', 'description'], | ||
['root', 'comment', 'description'], | ||
['root', 'comment', 'description'], | ||
['root', 'comment', 'description'], | ||
['root', 'comment', 'description'], | ||
['root', 'comment'], | ||
['root'], | ||
['root', 'comment'], | ||
['root'], | ||
['root', 'comment'], | ||
['root'], | ||
['root', 'comment'], | ||
['root', 'comment'], | ||
['root'], | ||
['root', 'comment'], | ||
['root', 'comment'], | ||
['root', 'comment'], | ||
['root', 'comment'], | ||
['root'], | ||
[], | ||
['root', 'comment', 'description'], | ||
['root', 'comment', 'description'], | ||
['root', 'comment', 'description'], | ||
['root', 'comment'], | ||
['root'], | ||
['root', 'comment'], | ||
['root', 'comment'], | ||
['root'], | ||
[], | ||
[] | ||
] | ||
|
||
/** | ||
* Nodes visited during postorder traversal. | ||
* | ||
* @const {Readonly<Postorder>} postorder | ||
*/ | ||
const postorder: Readonly<Postorder> = Object.freeze({ | ||
ancestors, | ||
parents, | ||
types, | ||
typesReversed | ||
}) | ||
|
||
export default postorder |
Oops, something went wrong.