/remove_duplicates

JavaScript: removing duplicated elements in an array without sorting it

Primary LanguageJavaScriptMIT LicenseMIT

Removing duplicates from an array

JavaScript: removing duplicated elements in an array without sorting them.

Usage

r_d(the_array)

It's recommended to use the latest remove_duplicate_shorter.js

That version won't change the original order of the array elements.

Example

var array = [1, 2, 3, 4, "doo", "dee", "doo", "♪", "doo"],
    trimmed = r_d(array);

// *trimmed* variable output will be an array.
// It consists of [1, 2, 3, 4, "doo, "dee", "♪"]

Additional

The "remove_duplicate_obj.js" version will return the sorted array.

It will also return an array without the duplications.

The 1st version (longer snippet) was the initial tinkering. It has the same output as the "shorter" version but has longer lines of code.

Idea explanation (JavaScript) and Python snippet

  1. Kinda an explanation on Monkey Raptor.

  2. Python equivalency post on Monkey Raptor.