Skip to content

Instantly share code, notes, and snippets.

@quantumJLBass
Created March 2, 2019 18:14
Show Gist options
  • Save quantumJLBass/fe41c656323dc32433f8c48558c8714b to your computer and use it in GitHub Desktop.
Save quantumJLBass/fe41c656323dc32433f8c48558c8714b to your computer and use it in GitHub Desktop.
flatten arrays
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
/*
* 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]]);
$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