Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created May 30, 2021 13:56
Show Gist options
  • Save MohammedALREAI/e731a508f89afa1bb9f53afae7fd50c8 to your computer and use it in GitHub Desktop.
Save MohammedALREAI/e731a508f89afa1bb9f53afae7fd50c8 to your computer and use it in GitHub Desktop.
simple calcalater in ts
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