Skip to content
Hannes Hirzel edited this page Dec 6, 2016 · 11 revisions

Welcome to the LearnWords2 Developer notes wiki!

BoxOfQuestions API notes

https://github.com/hhzl/LearnWords2/issues/46 has

chooseRandomWord() returns a random word object which has a date value which is less or equal to now. returns null if no such word is left https://github.com/hhzl/LearnWords2/issues/59

/**
 * Returns a random integer between min (inclusive) and max (inclusive)
 * Using Math.round() will give you a non-uniform distribution!
 */
function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

http://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range

// Returns a random integer between min (included) and max (included)
// Using Math.round() will give you a non-uniform distribution!
function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random

LWdb API notes

LWdb.put(aWord)

What happens in the following scenario?

var db = new LWdb("LW");
var newWord = { "word": "melon", "translate": "die Melone" };
db.put(newWord);
db.put(newWord);

As of 2nd Dec 2016 this will result in the same word stored twice for exactly this code. Because newWord does not have an _id field an _id field is assigned two times in the put method.

But currently new words are added with the loadWords(theWords) function (see below) and that function does not do that.

Later on when words are retrieved from the database they will have an _id field and thus storing the same word again will not result in duplication.

At the moment we only have as main use case

"use strict";
var LW = function(){

    var db = new LWdb('learnWords');

    db.loadWords(....)

    var box = new LWBoxOfQuestions(db);

    return box
}();

So storing the same word without an _id field twice will not happen.

https://github.com/hhzl/LearnWords2/issues/5 has

anLWdb.put({
  _id: 10,
  word: 'Apfel',
  answer: 'apple',
})

and a note that the requirement is that the object has an _id key.

The regular case is that if words are loaded with

 db.loadWords(theWords)

or the synonym

 db.importFrom(theWords);

db.put(aWord) is used. In the case there are no keys they are assigned.

For release 0.1 and release 0.2 this does not require action.

Clone this wiki locally