Skip to content

Commit

Permalink
Merge pull request ded#64 from dustinsenos/uniq
Browse files Browse the repository at this point in the history
make uniq work when it gets minified
  • Loading branch information
ded committed Dec 12, 2011
2 parents af6b96e + 059ad6c commit 69a6149
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
16 changes: 9 additions & 7 deletions qwery.js
Expand Up @@ -226,15 +226,17 @@
}

function uniq(ar) {
var a = [], i, j;
label:
for (i = 0; i < ar.length; i++) {
for (j = 0; j < a.length; j++) {
if (a[j] == ar[i]) continue label;
var r = [], i = 0, j = 0, k, item, inIt
for (; item = ar[i]; ++i) {
inIt = false
for (k = 0; k < r.length; ++k) {
if (r[k] === item) {
inIt = true; break
}
}
a[a.length] = ar[i]
if (!inIt) r[j++] = item
}
return a
return r
}

function arrayLike(o) {
Expand Down
2 changes: 1 addition & 1 deletion qwery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/qwery.js
Expand Up @@ -219,15 +219,17 @@
}

function uniq(ar) {
var a = [], i, j;
label:
for (i = 0; i < ar.length; i++) {
for (j = 0; j < a.length; j++) {
if (a[j] == ar[i]) continue label;
var r = [], i = 0, j = 0, k, item, inIt
for (; item = ar[i]; ++i) {
inIt = false
for (k = 0; k < r.length; ++k) {
if (r[k] === item) {
inIt = true; break
}
}
a[a.length] = ar[i]
if (!inIt) r[j++] = item
}
return a
return r
}

function arrayLike(o) {
Expand Down
4 changes: 2 additions & 2 deletions tests/index.html
Expand Up @@ -17,7 +17,7 @@
return 'success'
}
</script>
<script src="../src/qwery.js"></script>
<script src="../qwery.min.js"></script>
<script src="../src/pseudos.js"></script>
<script type="text/javascript">
var Q = qwery.noConflict()
Expand Down Expand Up @@ -118,7 +118,7 @@ <h1>Qwery Tests</h1>
<div class="sibling-selector"></div>
</div>
</div>

<div class="parent">
<h1 class="sibling oldest"></h1>
<h2 class="sibling older"></h2>
Expand Down
10 changes: 9 additions & 1 deletion tests/tests.js
Expand Up @@ -30,8 +30,9 @@ sink('Contexts', function (test, ok) {
ok(Q('.b', Q('#boosh .b')).length == 0, 'context found 0 elements(.b, #boosh .b)');
});

test('should not return duplicates from combinators', 1, function () {
test('should not return duplicates from combinators', 2, function () {
ok(Q('#boosh,#boosh').length == 1, 'two booshes dont make a thing go right');
ok(Q('#boosh,.apples,#boosh').length == 1, 'two booshes and an apple dont make a thing go right');
});

test('byId sub-queries within context', 6, function() {
Expand Down Expand Up @@ -270,6 +271,13 @@ sink('attribute selectors', function (test, ok, b, a, assert) {

});

sink('Uniq', function (test, ok) {
test('duplicates arent found in arrays', 2, function () {
ok(Q.uniq(['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e']).length == 5, 'result should be a, b, c, d, e')
ok(Q.uniq(['a', 'b', 'c', 'c', 'c']).length == 3, 'result should be a, b, c')
})
})

sink('element-context queries', function(test, ok) {
test('relationship-first queries', 5, function() {
var pass = false
Expand Down

0 comments on commit 69a6149

Please sign in to comment.