Symmetric Difference

    0

    0

    Giovanny Gongora

    Codiga's TypeScript Recipes

    Returns the symmetric difference between two arrays, without filtering out duplicate values.

    const symmetricDifference = (a: Array<number>, b: Array<number>) => {
      const sA: Set<number> = new Set(a),
        sB: Set<number> = new Set(b);
      return [...a.filter(x => !sB.has(x)), ...b.filter(x => !sA.has(x))];
    };
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.