Skip to content

Commit d25a8c5

Browse files
committed
Refactor to ignore iterator return values
1 parent 2ae9a80 commit d25a8c5

2 files changed

Lines changed: 1 addition & 296 deletions

File tree

lib/node_modules/@stdlib/iter/unique-by-hash/lib/main.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
2424
var isFunction = require( '@stdlib/assert/is-function' );
2525
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
26-
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2726
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
2827

2928

@@ -121,7 +120,6 @@ function iterUniqueByHash( iterator, hashFcn, thisArg ) {
121120
* @returns {Object} iterator protocol-compliant object
122121
*/
123122
function next() {
124-
var out;
125123
var hv;
126124
var v;
127125
if ( FLG ) {
@@ -133,15 +131,7 @@ function iterUniqueByHash( iterator, hashFcn, thisArg ) {
133131
v = iterator.next();
134132
if ( v.done ) {
135133
FLG = true;
136-
out = {};
137-
if ( hasOwnProp( v, 'value' ) ) {
138-
hv = hashFcn.call( thisArg, v.value );
139-
if ( contains( hash, hv ) === false ) {
140-
out.value = v.value;
141-
}
142-
}
143-
out.done = true;
144-
return out;
134+
return v;
145135
}
146136
hv = hashFcn.call( thisArg, v.value );
147137
if ( contains( hash, hv ) === false ) {

lib/node_modules/@stdlib/iter/unique-by-hash/test/test.js

Lines changed: 0 additions & 285 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,6 @@ var noop = require( '@stdlib/utils/noop' );
2929
var iterUniqueByHash = require( './../lib' );
3030

3131

32-
// FUNCTIONS //
33-
34-
function createIterator( arr ) {
35-
var len;
36-
var it;
37-
var i;
38-
39-
len = arr.length;
40-
i = -1;
41-
42-
it = {};
43-
it.next = next;
44-
45-
return it;
46-
47-
function next() {
48-
var out;
49-
i += 1;
50-
if ( i < len ) {
51-
out = {};
52-
out.value = arr[ i ];
53-
out.done = ( i === len-1 );
54-
return out;
55-
}
56-
return {
57-
'done': true
58-
};
59-
}
60-
}
61-
62-
6332
// TESTS //
6433

6534
tape( 'main export is a function', function test( t ) {
@@ -338,211 +307,6 @@ tape( 'the function returns an iterator which returns unique values (objects)',
338307
}
339308
});
340309

341-
tape( 'the function returns an iterator protocol-compliant object (value+done)', function test( t ) {
342-
var expected;
343-
var values;
344-
var actual;
345-
var it;
346-
var i;
347-
348-
values = [ 4, 2, 1, 3 ];
349-
expected = [
350-
{
351-
'value': 4,
352-
'done': false
353-
},
354-
{
355-
'value': 2,
356-
'done': false
357-
},
358-
{
359-
'value': 1,
360-
'done': false
361-
},
362-
{
363-
'value': 3,
364-
'done': true
365-
}
366-
];
367-
368-
it = iterUniqueByHash( createIterator( values ), hashFcn );
369-
t.equal( it.next.length, 0, 'has zero arity' );
370-
371-
actual = [];
372-
for ( i = 0; i < values.length; i++ ) {
373-
actual.push( it.next() );
374-
}
375-
t.deepEqual( actual, expected, 'returns expected values' );
376-
t.end();
377-
378-
function hashFcn( v ) {
379-
return v.toString();
380-
}
381-
});
382-
383-
tape( 'the function returns an iterator which returns unique values (value+done)', function test( t ) {
384-
var expected;
385-
var values;
386-
var actual;
387-
var it;
388-
var i;
389-
390-
values = [ 2, 1, 2, 1, 1, 4, 4, 4, 3, 2, 1 ];
391-
expected = [
392-
{
393-
'value': 2,
394-
'done': false
395-
},
396-
{
397-
'value': 1,
398-
'done': false
399-
},
400-
{
401-
'value': 4,
402-
'done': false
403-
},
404-
{
405-
'value': 3,
406-
'done': false
407-
},
408-
{
409-
'done': true
410-
}
411-
];
412-
413-
it = iterUniqueByHash( createIterator( values ), hashFcn );
414-
t.equal( it.next.length, 0, 'has zero arity' );
415-
416-
actual = [];
417-
for ( i = 0; i < expected.length; i++ ) {
418-
actual.push( it.next() );
419-
}
420-
t.deepEqual( actual, expected, 'returns expected values' );
421-
t.end();
422-
423-
function hashFcn( v ) {
424-
return v.toString();
425-
}
426-
});
427-
428-
tape( 'the function returns an iterator which returns unique values (value+done)', function test( t ) {
429-
var expected;
430-
var values;
431-
var actual;
432-
var it;
433-
var i;
434-
435-
values = [ 2, 1, 2, 1, 1, 4, 4, 4, 3, 2, 1, 5 ];
436-
expected = [
437-
{
438-
'value': 2,
439-
'done': false
440-
},
441-
{
442-
'value': 1,
443-
'done': false
444-
},
445-
{
446-
'value': 4,
447-
'done': false
448-
},
449-
{
450-
'value': 3,
451-
'done': false
452-
},
453-
{
454-
'value': 5,
455-
'done': true
456-
}
457-
];
458-
459-
it = iterUniqueByHash( createIterator( values ), hashFcn );
460-
t.equal( it.next.length, 0, 'has zero arity' );
461-
462-
actual = [];
463-
for ( i = 0; i < expected.length; i++ ) {
464-
actual.push( it.next() );
465-
}
466-
t.deepEqual( actual, expected, 'returns expected values' );
467-
t.end();
468-
469-
function hashFcn( v ) {
470-
return v.toString();
471-
}
472-
});
473-
474-
tape( 'the function returns an iterator which returns unique values (value+done; objects)', function test( t ) {
475-
var expected;
476-
var values;
477-
var actual;
478-
var it;
479-
var i;
480-
481-
values = [
482-
{
483-
'v': 2
484-
},
485-
{
486-
'v': 1
487-
},
488-
{
489-
'v': 2
490-
},
491-
{
492-
'v': 4
493-
},
494-
{
495-
'v': 1
496-
},
497-
{
498-
'v': 4
499-
},
500-
{
501-
'v': 3
502-
}
503-
];
504-
expected = [
505-
{
506-
'value': {
507-
'v': 2
508-
},
509-
'done': false
510-
},
511-
{
512-
'value': {
513-
'v': 1
514-
},
515-
'done': false
516-
},
517-
{
518-
'value': {
519-
'v': 4
520-
},
521-
'done': false
522-
},
523-
{
524-
'value': {
525-
'v': 3
526-
},
527-
'done': true
528-
}
529-
];
530-
531-
it = iterUniqueByHash( createIterator( values ), hashFcn );
532-
t.equal( it.next.length, 0, 'has zero arity' );
533-
534-
actual = [];
535-
for ( i = 0; i < expected.length; i++ ) {
536-
actual.push( it.next() );
537-
}
538-
t.deepEqual( actual, expected, 'returns expected values' );
539-
t.end();
540-
541-
function hashFcn( v ) {
542-
return JSON.stringify( v );
543-
}
544-
});
545-
546310
tape( 'the function supports providing a function evaluation context', function test( t ) {
547311
var expected;
548312
var values;
@@ -596,55 +360,6 @@ tape( 'the function supports providing a function evaluation context', function
596360
}
597361
});
598362

599-
tape( 'the function supports providing a function evaluation context (value+done)', function test( t ) {
600-
var expected;
601-
var values;
602-
var actual;
603-
var ctx;
604-
var it;
605-
var i;
606-
607-
values = [ 2, 1, 4, 3 ];
608-
ctx = {
609-
'count': 0
610-
};
611-
expected = [
612-
{
613-
'value': 2,
614-
'done': false
615-
},
616-
{
617-
'value': 1,
618-
'done': false
619-
},
620-
{
621-
'value': 4,
622-
'done': false
623-
},
624-
{
625-
'value': 3,
626-
'done': true
627-
}
628-
];
629-
630-
it = iterUniqueByHash( createIterator( values ), hashFcn, ctx );
631-
t.equal( it.next.length, 0, 'has zero arity' );
632-
633-
actual = [];
634-
for ( i = 0; i < values.length; i++ ) {
635-
actual.push( it.next() );
636-
}
637-
t.deepEqual( actual, expected, 'returns expected values' );
638-
639-
t.equal( ctx.count, 4, 'returns expected value' );
640-
t.end();
641-
642-
function hashFcn( v ) {
643-
this.count += 1; // eslint-disable-line no-invalid-this
644-
return v.toString();
645-
}
646-
});
647-
648363
tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) {
649364
var it;
650365
var r;

0 commit comments

Comments
 (0)