Created
May 30, 2021 13:56
-
-
Save MohammedALREAI/e731a508f89afa1bb9f53afae7fd50c8 to your computer and use it in GitHub Desktop.
simple calcalater in ts
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
type Operation="+"|"-"|"*"|"/" | |
function calcalater(a:Array<number>=[1,2,3],b:Array<number>=[5,2,3],operation:Operation='-'){ | |
let len=a.length>=b.length?a.length:b.length | |
let res:Array<number>=[] | |
for(let i=0;i<len;i++){ | |
let first | |
let secand | |
if(operation==='+' ||operation==="-"){ | |
first=a[i]?a[i]:0 | |
secand=b[i]?b[i]:0 | |
let tow=operation==="+"?first+secand:first-secand | |
res.push(tow) | |
} | |
else{ | |
first=a[i]?a[i]:1 | |
secand=a[i]?b[i]:1 | |
let tow=operation==="*"?first*secand:Math.floor(first/secand) | |
res.push(tow) | |
} | |
} | |
return res | |
} | |
console.log(calcalater()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment