Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- TABLESPACE
- isSquare
- JDBC
- manifest.json
- IBM
- descendingOrder
- react
- react hook
- custom hook
- Debug
- codewar
- useEffect
- java api
- TypeScript
- DB2
- codewars
- type
Archives
- Today
- Total
taesik
Coordinates Validator 본문
Valid coordinates look like the following: "23.32353342, -32.543534534". The return value should be either true or false.
Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative.
Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __
export function isValidCoordinates(coordinates:string):boolean{
const pattern = /^-?(90|[0-8]\d|\d)(?:\.\d*)?,\s-?(1[0-7]\d|180|\d{1,2})(?:\.\d*)?$/
return pattern.test(coordinates);
}
export function isValidCoordinates(coordinates: string): boolean {
const [lat, lng] = coordinates.split(', ').map(Number);
return lat > -90 && lat < 90 && lng > -180 && lng < 180;
}'functions and trick > typescript_javascript' 카테고리의 다른 글
| Consecutive strings (0) | 2022.01.29 |
|---|---|
| digitRoot (0) | 2022.01.29 |
| Count Friday 13th given year (0) | 2022.01.28 |
| Tribonacci (0) | 2022.01.28 |
| temp (0) | 2022.01.26 |