Created
January 3, 2014 16:48
-
-
Save asciidisco/8241400 to your computer and use it in GitHub Desktop.
Converting this line of perl to javascript...
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
@{$hashQ->{apIDs}}=grep !/$id/,@{$hashQ->{apIDs}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's a lot of concept in one line:
a) grep /stuff/ @{ ... } greps for stuff in the array which is referenced in the hash by the key apIDs
b) this is filtered by stuff NOT in said array and re-assigned as the same key referencing an array again.
So it filters aus non-existing IDs from apIDs and creates a new list for apIDs - but in a somewhat nested data structure.
In general, the grep construct is extremely common to filter things.
In more lines:
my @ids = @{ $hashQ->{apIDs} };
my @filtered_ids = grep { !$id } @ids;
$hashQ->{apIDs} = @filtered_ids;