Skip to content

Instantly share code, notes, and snippets.

@stafa-san
Created September 22, 2021 14:20
Show Gist options
  • Save stafa-san/cbc7cd50b776e6012b6a21a5fac18b18 to your computer and use it in GitHub Desktop.
Save stafa-san/cbc7cd50b776e6012b6a21a5fac18b18 to your computer and use it in GitHub Desktop.
Form Interview 2
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