Skip to main content
Converting Code to Demo
Source Link
dota2pro
  • 7.7k
  • 8
  • 49
  • 87

This is an ECMAScript 6 solution using spread operator and array generics.

Currently it only works with Firefox, and possibly Internet Explorer Technical Preview.

But if you use Babel, you can have it now.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe(arr)
{
  return [...new Set([].concat(...arr))];
}

const input = [
  [1, 2, 3],
  [101, 2, 1, 10],
  [2, 1]
];
const mergeDedupe = (arr) => {
  return [...new Set([].concat(...arr))];
}

console.log('output', mergeDedupe(input));

This is an ECMAScript 6 solution using spread operator and array generics.

Currently it only works with Firefox, and possibly Internet Explorer Technical Preview.

But if you use Babel, you can have it now.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe(arr)
{
  return [...new Set([].concat(...arr))];
}

This is an ECMAScript 6 solution using spread operator and array generics.

Currently it only works with Firefox, and possibly Internet Explorer Technical Preview.

But if you use Babel, you can have it now.

const input = [
  [1, 2, 3],
  [101, 2, 1, 10],
  [2, 1]
];
const mergeDedupe = (arr) => {
  return [...new Set([].concat(...arr))];
}

console.log('output', mergeDedupe(input));

Active reading.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

es6This is an ECMAScript 6 solution using spread operator and array generics.
Currently

Currently it only works with Firefox, and possibly IEInternet Explorer Technical Preview. But

But if you use Babel, you can have it now.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe( arr )
{
  return [ ...new Set( [].concat( ...arr ) ) ];
}

es6 solution using spread operator and array generics.
Currently only works with Firefox, and possibly IE Technical Preview. But if you use Babel, you can have it now.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe( arr )
{
  return [ ...new Set( [].concat( ...arr ) ) ];
}

This is an ECMAScript 6 solution using spread operator and array generics.

Currently it only works with Firefox, and possibly Internet Explorer Technical Preview.

But if you use Babel, you can have it now.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe(arr)
{
  return [...new Set([].concat(...arr))];
}
Remove Array in favor of [], and add guidance on how to be able to use in your app today.
Source Link
cmcculloh
  • 48.3k
  • 42
  • 107
  • 136

es6 solution using spread operator and array generics.
Currently only works with Firefox, and possibly IE Technical Preview. But if you use Babel, you can have it now.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe( arr )
{
  return [ ...new Set( Array[].concat( ...arr ) ) ];
}

es6 solution using spread operator and array generics.
Currently only works with Firefox, and possibly IE Technical Preview.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe( arr )
{
  return [ ...new Set( Array.concat( ...arr ) ) ];
}

es6 solution using spread operator and array generics.
Currently only works with Firefox, and possibly IE Technical Preview. But if you use Babel, you can have it now.

// Input: [ [1, 2, 3], [101, 2, 1, 10], [2, 1] ]
// Output: [1, 2, 3, 101, 10]
function mergeDedupe( arr )
{
  return [ ...new Set( [].concat( ...arr ) ) ];
}
added 85 characters in body
Source Link
Adria
  • 8.9k
  • 4
  • 38
  • 30
Loading
added 112 characters in body
Source Link
Adria
  • 8.9k
  • 4
  • 38
  • 30
Loading
Source Link
Adria
  • 8.9k
  • 4
  • 38
  • 30
Loading