Last active
March 8, 2017 03:57
-
-
Save entrypointkr/066b6e9e52bc18938d60f19e829499cc to your computer and use it in GitHub Desktop.
CommandHelper subset_of() Procedure
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
proc _subset_of(@arrayA, @arrayB) { | |
if (!is_array(@arrayA) || !is_array(@arrayB) || | |
is_associative(@arrayA) != is_associative(@arrayB)) { | |
return(false) | |
} | |
foreach (@key : @valueA in @arrayA) { | |
@valueB = array_get(@arrayB, @key, null) | |
if (@valueB == null | |
|| typeof(@valueB) != typeof(@valueA)) { | |
return(false) | |
} | |
if (is_array(@valueB) && !_subset_of(@valueA, @valueB)) { | |
return(false) | |
} else if (!equals(@valueA, @valueB)) { | |
return (false) | |
} | |
} | |
return(true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment