chikamichi / typometer

A silly micro-app to teach myself some FRP using Cycle.js — can you type that fast?
https://typometer.netlify.com/
MIT License
0 stars 0 forks source link

Weird issue with getter in divison #1

Closed chikamichi closed 6 years ago

chikamichi commented 6 years ago

Switching from:

  // model.ts
  private compute_wpm(attributes?: AppState): number {
    const a = attributes || this.model.attributes
    if (!a.stop) return 0
    const nb_words = a.keystrokes_nb / 5 // notice the hard-coded value
    const elapsed = (a.stop.getTime() - a.start.getTime()) / 1000 / 60 // minutes
    return Math.round(nb_words / elapsed)
  }

to:

  get word_length(): number {
    return 5
  }

  private compute_wpm(attributes?: AppState): number {
    const a = attributes || this.model.attributes
    if (!a.stop) return 0
    const nb_words = a.keystrokes_nb / this.word_length
    const elapsed = (a.stop.getTime() - a.start.getTime()) / 1000 / 60 // minutes
    return Math.round(nb_words / elapsed)
  }

returns 0. Same weirdness with a public and/or traditional function, or with a float instead of an integer.

chikamichi commented 6 years ago

Note: might not be a good idea having a text-dependent word length anyway.