Skip to content

Instantly share code, notes, and snippets.

@gr0uch
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save gr0uch/e7f7146735d7aec2f795 to your computer and use it in GitHub Desktop.

Select an option

Save gr0uch/e7f7146735d7aec2f795 to your computer and use it in GitHub Desktop.

Revisions

  1. 0x8890 revised this gist Aug 14, 2015. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions union.js
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,8 @@
    * @return {Set}
    */
    function union () {
    return new Set(Array.prototype.reduce.call(arguments,
    (memo, array) => {
    memo.push(...array)
    return memo
    }, []))
    return new Set(arguments[0].concat(
    ...Array.prototype.slice.call(arguments, 1)))
    }

    console.log(union([1, 2, 3], [2, 3, 4])) // => [1, 2, 3, 4]
  2. 0x8890 revised this gist Aug 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion union.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    /**
    * Get the union of arrays with unique values by means of the Set type.
    *
    * @param {Array}
    * @param {Array[]}
    * @return {Set}
    */
    function union () {
  3. gr0uch revised this gist May 2, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions union.js
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,14 @@
    * Get the union of arrays with unique values by means of the Set type.
    *
    * @param {Array}
    * @return {Array}
    * @return {Set}
    */
    function union () {
    return [...new Set(Array.prototype.reduce.call(arguments,
    return new Set(Array.prototype.reduce.call(arguments,
    (memo, array) => {
    memo.push(...array)
    return memo
    }, []))]
    }, []))
    }

    console.log(union([1, 2, 3], [2, 3, 4])) // => [1, 2, 3, 4]
  4. gr0uch revised this gist May 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion union.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    * @param {Array}
    * @return {Array}
    */
    export default function union () {
    function union () {
    return [...new Set(Array.prototype.reduce.call(arguments,
    (memo, array) => {
    memo.push(...array)
  5. gr0uch revised this gist May 2, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions union.js
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,11 @@
    * @return {Array}
    */
    export default function union () {
    return [...new Set(Array.prototype.reduce.call(arguments, (memo, array) => {
    memo.push(...array)
    return memo
    }, []))]
    return [...new Set(Array.prototype.reduce.call(arguments,
    (memo, array) => {
    memo.push(...array)
    return memo
    }, []))]
    }

    console.log(union([1, 2, 3], [2, 3, 4])) // => [1, 2, 3, 4]
  6. gr0uch revised this gist May 2, 2015. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions union.js
    Original file line number Diff line number Diff line change
    @@ -5,12 +5,10 @@
    * @return {Array}
    */
    export default function union () {
    return [...new Set([
    ...Array.prototype.reduce.call(arguments, (memo, array) => {
    memo.push(...array)
    return memo
    }, [])
    ])]
    return [...new Set(Array.prototype.reduce.call(arguments, (memo, array) => {
    memo.push(...array)
    return memo
    }, []))]
    }

    console.log(union([1, 2, 3], [2, 3, 4])) // => [1, 2, 3, 4]
  7. gr0uch revised this gist May 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion union.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /**
    * Get the union of arrays with unique values by abusing the Set type.
    * Get the union of arrays with unique values by means of the Set type.
    *
    * @param {Array}
    * @return {Array}
  8. gr0uch created this gist May 2, 2015.
    16 changes: 16 additions & 0 deletions union.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /**
    * Get the union of arrays with unique values by abusing the Set type.
    *
    * @param {Array}
    * @return {Array}
    */
    export default function union () {
    return [...new Set([
    ...Array.prototype.reduce.call(arguments, (memo, array) => {
    memo.push(...array)
    return memo
    }, [])
    ])]
    }

    console.log(union([1, 2, 3], [2, 3, 4])) // => [1, 2, 3, 4]