Created
January 30, 2015 20:05
-
-
Save navio/5acc66fb8f9d35c5841c to your computer and use it in GitHub Desktop.
EBook Reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* E-Reader | |
* | |
* 0. Define the Ebook | |
* | |
* 1. Lets create a feature: the appendix feature | |
* | |
* An appendix is: a list of all the words in the book | |
* in alphabetical order, along wth the page # on which each | |
* word appears. e.g.: | |
* | |
* ------- Lé Appendix -------- | |
* Apple: 1,2,7 | |
* Banana: 1,5 | |
* .... | |
* Zebra: 17,19 | |
*/ | |
var page = function (){ | |
words = ""; | |
function create(words){ | |
this.words = words; | |
} | |
function words_iterator(){ | |
return next.pop(); | |
} | |
return { | |
create: create, | |
next: words_iterator | |
} | |
} | |
var book = function(){ | |
var pages = []; | |
function create(book,wordsperPage){ | |
words_book = book.replace(_elementsNotWord).split(" "); | |
var page = []; | |
var current_page = 0; | |
for(word in words_book){ | |
page.push(word); | |
if(word === wordsperPage ){ | |
pages[current_page] = page ; | |
page = []; | |
current_page++; | |
} | |
} | |
} | |
} | |
var myBook = Object.create('book'); | |
myBook.create(data); | |
(function(book){ | |
var _elementsNotWord = "/,."; | |
function wordCollector(){ | |
var words []; | |
for(page in book.pages){ | |
for(word in page){ | |
if(words.indexOf(word[i]) == -1 ){ | |
var array_page = [page]; | |
words[words_in_theBook[i]] = array_page; | |
}else{ | |
// the word exist | |
words[words_in_theBook[i]].push(page); | |
} | |
} | |
} | |
return words[]; | |
} | |
})(myBook, page_size ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment