Created
April 20, 2021 07:59
-
-
Save MohammedALREAI/5db67c7bc3a0d82286dd1e7c74b4bf5c to your computer and use it in GitHub Desktop.
numberSigningSum
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
function numberSigningSums(num:number =5555531):any{ | |
let arr=[...String(num)].map(x=>Number(x)) | |
if(arr.length<2){ | |
return arr[0] | |
} | |
let sum=0 | |
for(let i=0;i<arr.length;i+=2){ | |
if(arr[i+1]){ | |
sum+=arr[i]-arr[i+1] | |
} | |
else{ | |
sum+=arr[i] | |
} | |
} | |
return sum | |
} | |
console.log(numberSigningSums()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment