Skip to content

Commit 8251eaa

Browse files
committed
Fix to invert result order
Closes GH-6.
1 parent 86c5b5c commit 8251eaa

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = findAllBefore
77
function findAllBefore(parent, index, test) {
88
var is = convert(test)
99
var results = []
10+
var offset = -1
1011

1112
if (!parent || !parent.type || !parent.children) {
1213
throw new Error('Expected parent node')
@@ -29,9 +30,9 @@ function findAllBefore(parent, index, test) {
2930
index = parent.children.length
3031
}
3132

32-
while (index--) {
33-
if (is(parent.children[index], index, parent)) {
34-
results.push(parent.children[index])
33+
while (++offset < index) {
34+
if (is(parent.children[offset], offset, parent)) {
35+
results.push(parent.children[offset])
3536
}
3637
}
3738

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ test('unist-util-find-all-before', function (t) {
133133
'should return children when given a `type` and existing (#4)'
134134
)
135135

136-
var result = children.slice(4).reverse()
136+
var result = children.slice(4)
137137

138138
t.deepEqual(
139139
findAllBefore(paragraph, 100, test),

0 commit comments

Comments
 (0)