prototypes
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -32,11 +32,13 @@ 'use strict'; | ||
*/ | ||
newArray.unique = function() { | ||
var result = [], index = -1, value = null; | ||
while(++index < this.length) { | ||
value = this[index]; | ||
if((value || value === 0) && !result.contains(value)) { | ||
newArray.unique = function() | ||
{ | ||
var result = []; | ||
this.forEach(function(value) | ||
{ | ||
if (value !== null && value !== undefined && !result.contains(value)) | ||
{ | ||
result.push(value); | ||
} | ||
} | ||
return result.sort(); | ||
}); | ||
return result; | ||
}; | ||
@@ -43,0 +45,0 @@ |
{ | ||
"name": "prototypes", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Some common prototypes for node.js: string.startsWith(), object.countProperties() and more. Facilities for functional programming with objects: object.forEach(), object.filter(). Functions are added safely using Object.defineProperty().", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/alexfernandez/prototypes", |
@@ -312,3 +312,3 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/prototypes.png)](http://travis-ci.org/alexfernandez/prototypes) | ||
Returns a new sorted array of unique elements. | ||
Returns a new array of unique elements. | ||
Throws out null and undefined elements. Example: | ||
@@ -318,3 +318,3 @@ | ||
['c', 'a', 'b', 'c', 'b'].unique(); | ||
\=> ['a', 'b', 'c'] | ||
\=> ['c', 'a', 'b'] | ||
``` | ||
@@ -321,0 +321,0 @@ |
@@ -22,15 +22,12 @@ 'use strict'; | ||
function testUnique(callback) { | ||
function testUnique(callback) | ||
{ | ||
var array = []; | ||
testing.assertEquals(array.unique(), [], 'Array should be empty', callback); | ||
array = [4,1,6]; | ||
testing.assertEquals(array.unique(), [1,4,6], '', callback); | ||
array = [4,1,6,9,0,5,9,9,9,9,5,5,5,1,1,4]; | ||
testing.assertEquals(array.unique(), [0,1,4,5,6,9], '', callback); | ||
array = [4, 1, 6]; | ||
testing.assertEquals(array.unique(), [4, 1, 6], 'Not sorted', callback); | ||
array = [4, 1, 6, 9, 0, 5, 9, 9, 9, 9, 5, 5, 5, 1, 1, 4]; | ||
testing.assertEquals(array.unique(), [4, 1, 6, 9, 0, 5], 'Longer not sorted', callback); | ||
array = [null, null, 3, null, 3]; | ||
testing.assertEquals(array.unique(), [3], 'Null test', callback); | ||
array = [0, undefined, null]; | ||
@@ -37,0 +34,0 @@ testing.assertEquals(array.unique(), [0], 'Falsey test', callback); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44084
1180