Skip to content

Instantly share code, notes, and snippets.

@MrBisquit
Last active November 24, 2023 20:40
Show Gist options
  • Save MrBisquit/e5346c5e5230a5b4672de8e567a5d126 to your computer and use it in GitHub Desktop.
Save MrBisquit/e5346c5e5230a5b4672de8e567a5d126 to your computer and use it in GitHub Desktop.
Minimalistic TS code
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; }
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; }
const powerOf = (n: number, powerOf: number) => { var num: number = n; for (var i = 0; i <= powerOf + 1; i++) { num += n; }; return num; }
const removeDecimal = (n: number) => { return parseInt(`${n}`.split('.')[0]); }
const squareRoot = (n: number) => { let g = n/2; for(var i = 0; i < 10; i++) { g = 0.5 * (g + n / g); } return g; }
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