Skip to main content
Module

x/rimbu/typical/mod.ts>StrNum.SubDigit

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
type alias StrNum.SubDigit
import { type StrNum } from "https://deno.land/x/rimbu@0.13.1/typical/mod.ts";
const { SubDigit } = StrNum;

Given two string digits, returns a tuple of which the first element is the resulting digit from subtracting the second from the first, and the second element a boolean that is true if there is an 'underflow' or borrow, never otherwise.

Examples

Example 1

SubDigit<'5', '3'> => ['2', never]
SubDigit<'3', '6'> => ['7', true]

Type Parameters

D1 extends Digit
D2 extends Digit
definition: D2 extends "0" ? [D1, false] : D1 extends D2 ? ["0", false] : Str.Append<D1, D2> extends infer DD ? DD extends
| "09"
| "21"
| "32"
| "43"
| "54"
| "65"
| "76"
| "87"
| "98"
? ["1", U.Extends<DD, "09">] : DD extends
| "08"
| "19"
| "31"
| "42"
| "53"
| "64"
| "75"
| "86"
| "97"
? ["2", U.Extends<DD, "08" | "19">] : DD extends
| "07"
| "18"
| "29"
| "41"
| "52"
| "63"
| "74"
| "85"
| "96"
? ["3", U.Extends<DD, "07" | "18" | "29">] : DD extends
| "06"
| "17"
| "28"
| "39"
| "51"
| "62"
| "73"
| "84"
| "95"
? ["4", U.Extends<DD,
| "06"
| "17"
| "28"
| "39"
>]
: DD extends
| "05"
| "16"
| "27"
| "38"
| "49"
| "61"
| "72"
| "83"
| "94"
? ["5", U.Extends<DD,
| "05"
| "16"
| "27"
| "38"
| "49"
>]
: DD extends
| "04"
| "15"
| "26"
| "37"
| "48"
| "59"
| "71"
| "82"
| "93"
? ["6", U.Extends<DD,
| "04"
| "15"
| "26"
| "37"
| "48"
| "59"
>]
: DD extends
| "03"
| "14"
| "25"
| "36"
| "47"
| "58"
| "69"
| "81"
| "92"
? ["7", U.Extends<DD,
| "03"
| "14"
| "25"
| "36"
| "47"
| "58"
| "69"
>]
: DD extends
| "02"
| "13"
| "24"
| "35"
| "46"
| "57"
| "68"
| "79"
| "91"
? ["8", U.Extends<DD,
| "02"
| "13"
| "24"
| "35"
| "46"
| "57"
| "68"
| "79"
>]
: DD extends
| "01"
| "12"
| "23"
| "34"
| "45"
| "56"
| "67"
| "78"
| "89"
? ["9", true] : never : never