Created
September 22, 2021 14:20
-
-
Save stafa-san/cbc7cd50b776e6012b6a21a5fac18b18 to your computer and use it in GitHub Desktop.
Form Interview 2
This file contains 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
const wholeNumbers = new Set(); | |
function getUniqueSortedNumbers(arr) { | |
for (words in arr) { | |
if (typeof arr[words] === 'number') { | |
wholeNumbers.add(arr[words]); | |
} | |
getUniqueSortedNumbers(arr[words]); | |
} | |
return Array.from(wholeNumbers).sort(); | |
} | |
console.log( | |
getUniqueSortedNumbers({ | |
a: { | |
x: 3, | |
y: { | |
d: 2, | |
e: 2, | |
f: { | |
g: 4 | |
}, | |
z: 8 | |
} | |
} | |
}) | |
); // [2, 3, 4, 8]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment