Skip to content

Instantly share code, notes, and snippets.

@cyjake
Created December 13, 2013 09:13
Show Gist options
  • Save cyjake/7941752 to your computer and use it in GitHub Desktop.
Save cyjake/7941752 to your computer and use it in GitHub Desktop.
Array.unique?
var data = [{
sizes: [1, 0]
},{
sizes: [2, 3]
},{
sizes: [2, 2]
},{
sizes: [3, 5]
},{
sizes: [1, 0]
},{
sizes: [2, 2]
},{
sizes: [2, 3]
},{
sizes: [2.3, -2]
}]
// should output
// [ { sizes: [ 3, 5 ] },
// { sizes: [ 1, 0 ] },
// { sizes: [ 2, 2 ] },
// { sizes: [ 2, 3 ] },
// { sizes: [ 2.3, -2 ] } ]
@cyjake
Copy link
Author

cyjake commented Dec 16, 2013

var obj = {}

for (var i = data.length - 1; i >= 0; i--) {
    var sizes = '' + data[i].sizes

    if (obj[sizes]) {
        data.splice(i, 1)
    }
    else {
        obj[sizes] = true
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment