Skip to content

Instantly share code, notes, and snippets.

@entrypointkr
Last active March 8, 2017 03:57
Show Gist options
  • Save entrypointkr/066b6e9e52bc18938d60f19e829499cc to your computer and use it in GitHub Desktop.
Save entrypointkr/066b6e9e52bc18938d60f19e829499cc to your computer and use it in GitHub Desktop.
CommandHelper subset_of() Procedure
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