Skip to content

Commit 45ebc0f

Browse files
authored
Fixed Range not terminating
...when endpoints have differing decimals also moved collect down to terminators
1 parent 3dcb1d6 commit 45ebc0f

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

static/extensions/Div/divIterators.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@
164164
Iterables: {
165165
range(start, end) {
166166
const advance = n => n + (start < end ? 1 : -1);
167+
const finished = n => start < end ? (n >= end + 1) : (n <= end - 1)
167168
return new IteratorType({kind: "Range", args: [start, end]},
168169
{curr: start}, function*(state){
169170
const {curr} = state;
170-
if(curr == advance(end)) return divIterator.Done()
171+
if(finished(curr)) return divIterator.Done()
171172
state.curr = advance(curr);
172173
return divIterator.Item(curr)
173174
});
@@ -627,22 +628,6 @@
627628
},
628629
...divIterator.Block
629630
},
630-
{
631-
opcode: 'iterCollectTo',
632-
text: '[ITER] finally collect to [TYPE]',
633-
arguments: {
634-
ITER: divIterator.Argument,
635-
TYPE: {
636-
type: Scratch.ArgumentType.STRING,
637-
menu: "fromIter",
638-
defaultValue: "Array"
639-
}
640-
},
641-
disableMonitor: true,
642-
blockType: BlockType.REPORTER,
643-
blockShape: BlockShape.ROUND,
644-
allowDropAnywhere: true,
645-
},
646631

647632
'---',
648633
{
@@ -818,6 +803,22 @@
818803
blockType: BlockType.LABEL,
819804
text: 'Iterator Terminators'
820805
},
806+
{
807+
opcode: 'iterCollectTo',
808+
text: '[ITER] finally collect to [TYPE]',
809+
arguments: {
810+
ITER: divIterator.Argument,
811+
TYPE: {
812+
type: Scratch.ArgumentType.STRING,
813+
menu: "fromIter",
814+
defaultValue: "Array"
815+
}
816+
},
817+
disableMonitor: true,
818+
blockType: BlockType.REPORTER,
819+
blockShape: BlockShape.ROUND,
820+
allowDropAnywhere: true,
821+
},
821822
{
822823
opcode: 'iterTermCount',
823824
text: '[ITER] finally count items',

0 commit comments

Comments
 (0)