Created
April 1, 2024 16:23
-
-
Save jenyeeiam/ba148c2ae485e015b84898c5028dc1ac to your computer and use it in GitHub Desktop.
cassido 2024-04-01 submission
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 uniqueSum(arr) { | |
if(!arr || arr.length === 0){ | |
return 0 | |
} | |
const stringArr = arr.map(function(num) { | |
return num.toString(); | |
}) | |
let runningSum = 0; | |
stringArr.forEach(stringNum => { | |
if(!hasRepeatedDigits(stringNum)) { | |
runningSum += Number(stringNum) | |
} | |
}); | |
return runningSum; | |
} | |
function hasRepeatedDigits(stringNum) { | |
if(stringNum.length === 1) { | |
return false; | |
} | |
const setOfDigits = new Set(stringNum.split(' ')); | |
return stringNum.length !== setOfDigits.size; | |
} | |
console.log(uniqueSum([101,22,3])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment