Add: TypingTextManager - makeExaminationContents
This commit is contained in:
@@ -100,10 +100,51 @@ TypingTextManager.prototype.makeTestContents = function(arr) {
|
||||
|
||||
TypingTextManager.prototype.makeExaminationContents = function(arr) {
|
||||
this.init();
|
||||
|
||||
// getExaminationArray : slice too long sentence by proper words and last space
|
||||
this.add(arr);
|
||||
// this.add(arr);
|
||||
for(var i = 0; i < arr.length; i++) {
|
||||
var sentence = arr[i];
|
||||
if(sentence.length == 0)
|
||||
continue;
|
||||
if(sentence.length > TypingTextManager.SENTENCE_MAX_CHARACTER)
|
||||
this.add(this.makeShortSentences(sentence));
|
||||
else
|
||||
this.add(sentence);
|
||||
}
|
||||
}
|
||||
|
||||
TypingTextManager.prototype.makeShortSentences = function(sentence) {
|
||||
var words = sentence.split(" ");
|
||||
var wordCount = words.length;
|
||||
|
||||
var shortSentences = [];
|
||||
var sentenceIndex = 0;
|
||||
shortSentences[sentenceIndex] = "";
|
||||
|
||||
// console.log(sentence);
|
||||
// console.log(words);
|
||||
|
||||
for(var i = 0; i < wordCount; i++) {
|
||||
// console.log(words[i]);
|
||||
// console.log(shortSentences[sentenceIndex].length);
|
||||
// console.log(words[i]);
|
||||
if(shortSentences[sentenceIndex].length + words[i].length < TypingTextManager.SENTENCE_MAX_CHARACTER)
|
||||
if(i < wordCount - 1)
|
||||
shortSentences[sentenceIndex] = shortSentences[sentenceIndex].concat(words[i], " ");
|
||||
else // last word
|
||||
shortSentences[sentenceIndex] = shortSentences[sentenceIndex].concat(words[i]);
|
||||
else {
|
||||
sentenceIndex++;
|
||||
if(i < wordCount - 1)
|
||||
shortSentences[sentenceIndex] = words[i] + " ";
|
||||
else // last word
|
||||
shortSentences[sentenceIndex] = words[i];
|
||||
}
|
||||
}
|
||||
|
||||
return shortSentences;
|
||||
}
|
||||
|
||||
|
||||
TypingTextManager.shuffledArray = function(arr) {
|
||||
@@ -138,3 +179,6 @@ TypingTextManager.ENGLISH_LETTER_RIGHT = [
|
||||
"h", "j", "k", "l",
|
||||
"n", "m"
|
||||
];
|
||||
|
||||
|
||||
TypingTextManager.SENTENCE_MAX_CHARACTER = 27;
|
||||
Reference in New Issue
Block a user