Skip to content

Commit

Permalink
Use constant iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
drewsonne committed Dec 29, 2019
1 parent 327bb62 commit b33ba9a
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions src/operations/calendar-round-wildcard.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
const CalendarRound = require('../cr/calendar-round')
const wildcard = require('../wildcard')

class CalendarRoundWildcard {
/**
* @param {CalendarRound} cr
*/
constructor (cr) {
this.cr = cr
this.start_date = new CalendarRound(
4, 'Ajaw',
8, 'Kumk\'u',
)
}

run () {
let potentials = []
// Iterate through dates and compare
let iter = new CalendarRoundIterator()
let cr = iter.next()
while (!cr.done) {
if (this.cr.match(cr.value)) {
potentials.push(cr.value)
}
cr = iter.next()
}
return potentials
}

}
const origin = require('../cr/index').origin

class CalendarRoundIterator {
/**
Expand All @@ -36,12 +8,13 @@ class CalendarRoundIterator {
*/
constructor (date) {
if (date === undefined) {
date = new CalendarRound(
4, 'Ajaw',
8, 'Kumk\'u',
)
date = origin
}
this.date = date
this.reset()
}

reset () {
this.current = this.date
this.is_first = true
}
Expand All @@ -63,4 +36,30 @@ class CalendarRoundIterator {

}

const iter = new CalendarRoundIterator()

class CalendarRoundWildcard {
/**
* @param {CalendarRound} cr
*/
constructor (cr) {
this.cr = cr
}

run () {
let potentials = []
// Iterate through dates and compare
let cr = iter.next()
while (!cr.done) {
if (this.cr.match(cr.value)) {
potentials.push(cr.value)
}
cr = iter.next()
}
iter.reset()
return potentials
}

}

module.exports = CalendarRoundWildcard

0 comments on commit b33ba9a

Please sign in to comment.