forked from rylnd/decontext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecontext.js
More file actions
38 lines (30 loc) · 966 Bytes
/
decontext.js
File metadata and controls
38 lines (30 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$(function() {
var swapItems = function(array, index, otherIndex) {
var tempItem = array[index];
array[index] = array[otherIndex];
array[otherIndex] = tempItem;
return array;
},
randomNumber = function(min, max) {
return Math.floor(Math.random() * (max - min) + min);
},
shuffle = function(array) {
var randomRemainingIndex;
for (var index = 0; index < array.length; index++) {
randomRemainingIndex = randomNumber(index, array.length);
swapItems(array, index, randomRemainingIndex);
}
return array;
};
$('form').on('submit', function(e) {
e.preventDefault();
var $sentences = $('.sentences'),
text = $('[name=document]').val();
var sentences = text.split(/\.\s+/),
shuffledSentences = shuffle(sentences),
paragraphs = shuffledSentences.map(function(sentence) {
return "<p>" + sentence + ".</p>";
});
$sentences.html(paragraphs);
});
})