Last active
November 24, 2023 20:40
-
-
Save MrBisquit/e5346c5e5230a5b4672de8e567a5d126 to your computer and use it in GitHub Desktop.
Minimalistic TS code
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
const countVowels = (s: string) => { let v = 0; let ss = s.split(''); ss.forEach(c => { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { v++; } }); return v; } |
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
const getEvenNumbers = (amount: number) => { let arr: number[] = [] as number[]; let cn = 0; for (var i = 0; i < amount; i++) { if(cn % 2 == 0) { arr.push(cn); cn++; } else { cn++; i--; } } return arr; } |
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
const powerOf = (n: number, powerOf: number) => { var num: number = n; for (var i = 0; i <= powerOf + 1; i++) { num += n; }; return num; } |
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
const removeDecimal = (n: number) => { return parseInt(`${n}`.split('.')[0]); } |
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
const squareRoot = (n: number) => { let g = n/2; for(var i = 0; i < 10; i++) { g = 0.5 * (g + n / g); } return g; } |
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
const sumArray = (arr: number[]) => { let n = 0; arr.forEach(num => { n += num }); return n; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment