Skip to content

Instantly share code, notes, and snippets.

@entrypointkr
Last active March 8, 2017 03:57

Revisions

  1. entrypointkr revised this gist Mar 8, 2017. 1 changed file with 12 additions and 17 deletions.
    29 changes: 12 additions & 17 deletions auto_include.ms
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,19 @@
    proc _subset_of(@a, @b) {
    if (!is_array(@a) || !is_array(@b) ||
    is_associative(@a) != is_associative(@b)) {
    proc _subset_of(@arrayA, @arrayB) {
    if (!is_array(@arrayA) || !is_array(@arrayB) ||
    is_associative(@arrayA) != is_associative(@arrayB)) {
    return(false)
    }
    foreach (@key : @valueA in @a) {
    @valueB = array_get(@b, @key, null)
    if (@valueB == null ||
    typeof(@valueB) != typeof(@valueA)) {
    foreach (@key : @valueA in @arrayA) {
    @valueB = array_get(@arrayB, @key, null)
    if (@valueB == null
    || typeof(@valueB) != typeof(@valueA)) {
    return(false)
    }
    if (is_array(@valueB)) {
    if (is_associative(@valueA) != is_associative(@valueB) ||
    !_subset_of(@valueA, @valueB)) {
    return(false)
    }
    } else {
    if (!equals(@valueA, @valueB)) {
    return(false)
    }
    if (is_array(@valueB) && !_subset_of(@valueA, @valueB)) {
    return(false)
    } else if (!equals(@valueA, @valueB)) {
    return (false)
    }
    }
    return(true)
    }
    }
  2. entrypointkr revised this gist Dec 16, 2016. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions auto_include.ms
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    proc _subset_of(@a, @b) {
    if (!is_array(@a) || !is_array(@b)) {
    if (!is_array(@a) || !is_array(@b) ||
    is_associative(@a) != is_associative(@b)) {
    return(false)
    }
    foreach (@key : @valueA in @a) {
    @@ -9,7 +10,8 @@ proc _subset_of(@a, @b) {
    return(false)
    }
    if (is_array(@valueB)) {
    if (!_subset_of(@valueA, @valueB)) {
    if (is_associative(@valueA) != is_associative(@valueB) ||
    !_subset_of(@valueA, @valueB)) {
    return(false)
    }
    } else {
  3. entrypointkr revised this gist Dec 16, 2016. 1 changed file with 8 additions and 10 deletions.
    18 changes: 8 additions & 10 deletions auto_include.ms
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,22 @@
    proc _subset_of(@a, @b) {
    if (!is_array(@a) || !is_array(@b)) {
    return(false);
    return(false)
    }
    foreach (@key : @valueA in @a) {
    @valueB = array_get(@b, @key, null);
    if (@valueB == null) {
    return(false);
    }
    if (typeof(@valueB) != typeof(@valueA)) {
    return(false);
    @valueB = array_get(@b, @key, null)
    if (@valueB == null ||
    typeof(@valueB) != typeof(@valueA)) {
    return(false)
    }
    if (is_array(@valueB)) {
    if (!_subset_of(@valueA, @valueB)) {
    return(false);
    return(false)
    }
    } else {
    if (!equals(@valueA, @valueB)) {
    return(false);
    return(false)
    }
    }
    }
    return(true);
    return(true)
    }
  4. entrypointkr revised this gist Dec 15, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_include.ms
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ proc _subset_of(@a, @b) {
    if (@valueB == null) {
    return(false);
    }
    if (@valueB !== @valueA) {
    if (typeof(@valueB) != typeof(@valueA)) {
    return(false);
    }
    if (is_array(@valueB)) {
  5. entrypointkr created this gist Dec 15, 2016.
    24 changes: 24 additions & 0 deletions auto_include.ms
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    proc _subset_of(@a, @b) {
    if (!is_array(@a) || !is_array(@b)) {
    return(false);
    }
    foreach (@key : @valueA in @a) {
    @valueB = array_get(@b, @key, null);
    if (@valueB == null) {
    return(false);
    }
    if (@valueB !== @valueA) {
    return(false);
    }
    if (is_array(@valueB)) {
    if (!_subset_of(@valueA, @valueB)) {
    return(false);
    }
    } else {
    if (!equals(@valueA, @valueB)) {
    return(false);
    }
    }
    }
    return(true);
    }