Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 2.04 KB

File metadata and controls

25 lines (19 loc) · 2.04 KB

Percentage Parser medium #template-literal

by SSShuai1999 @SSShuai1999

Take the Challenge    简体中文 한국어

Implement PercentageParser. According to the /^(\+|\-)?(\d*)?(\%)?$/ regularity to match T and get three matches.

The structure should be: [plus or minus, number, unit] If it is not captured, the default is an empty string.

For example:

type PString1 = ""
type PString2 = "+85%"
type PString3 = "-85%"
type PString4 = "85%"
type PString5 = "85"

type R1 = PercentageParser<PString1> // expected ['', '', '']
type R2 = PercentageParser<PString2> // expected ["+", "85", "%"]
type R3 = PercentageParser<PString3> // expected ["-", "85", "%"]
type R4 = PercentageParser<PString4> // expected ["", "85", "%"]
type R5 = PercentageParser<PString5> // expected ["", "85", ""]

Back Share your Solutions Check out Solutions