Created
March 2, 2019 18:14
-
-
Save quantumJLBass/fe41c656323dc32433f8c48558c8714b to your computer and use it in GitHub Desktop.
flatten arrays
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
var values = new[] | |
{ | |
new[] { 1, 2 }, | |
new[] { 2, 3 }, | |
new[] { 4, 5 }, | |
}; | |
var flattenedUniqueValues = values.SelectMany(x => x).Distinct();//technically it handles none int too |
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
/* | |
* there are so many ways to skin this cat, but here is a simple one | |
*/ | |
const flattenJSON = array => | |
JSON.stringify(array) | |
.match(/\d+/g) | |
.map(x => parseInt(x)); | |
//flattenJSON([1,2,[1,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
$a = @(1, @(2, @(3))) | |
$a = $a | % {$_} | sort -unique #technically it handles none int too |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment