Last active
October 2, 2017 00:30
-
-
Save BehindTheMath/4c01ef1a6a79ca740b145e063cd17617 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // utils.ts | |
| export module MathUtils { | |
| export function degreesToRadians(degrees: number): number { | |
| return degrees * Math.PI / 180; | |
| } | |
| export function radiansToDegrees(radians: number): number { | |
| return radians * 180 / Math.PI; | |
| } | |
| }; | |
| export module StringUtils { | |
| export function replaceAll(string: string, searchString: string, replaceString: string): string { | |
| return string.split(searchString).join(replaceString); | |
| } | |
| export function compareTo(string1: string, string2: string): number { | |
| const len1: number = string1.length; | |
| const len2: number = string2.length; | |
| const lim: number = Math.min(len1, len2); | |
| const v1: string[] = string1.split(""); | |
| const v2: string[] = string2.split(""); | |
| let k: number = 0; | |
| while (k < lim) { | |
| const c1: string = v1[k]; | |
| const c2: string = v2[k]; | |
| if (c1 !== c2) { | |
| return c1.charCodeAt(0) - c2.charCodeAt(0); | |
| } | |
| k++; | |
| } | |
| return len1 - len2; | |
| } | |
| }; | |
| // ----------------------------------------------------- | |
| //index.ts | |
| import { MathUtils, StringUtils } from './utils'; | |
| console.log(MathUtils.add(2, 2)); | |
| console.log(StringUtils.concat('a', 'z')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment