-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpseudoRandomizeText.html
More file actions
61 lines (54 loc) · 1.23 KB
/
pseudoRandomizeText.html
File metadata and controls
61 lines (54 loc) · 1.23 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<HTML>
<HEAD>
<script>
function transformPhrase(phrase) {
phraseArray = phrase.split(' ');
for (var i=0; i<phraseArray.length; i++) {
phraseArray[i] = transformWord(phraseArray[i]);
}
return phraseArray.join(' ');
}
function transformWord(word) {
specialEndCharsArray = [
'.',
',',
':',
'-',
';'
];
for (var char of specialEndCharsArray) {
if ( word.endsWith(char) ) {
return transformWord(word.slice(0,-1)) + char;
}
}
if (word.length <= 2) {
return word;
}else{
return word[0]+shuffle(word.slice(1,-1))+word[word.length-1];
}
}
function shuffle (string) {
work_array = string.split('')
var i = 0
, j = 0
, temp = null
for (i = work_array.length - 1; i > 0; i -= 1) {
j = Math.floor(Math.random() * (i + 1));
temp = work_array[i];
work_array[i] = work_array[j];
work_array[j] = temp;
}
return work_array.join('');
}
</script>
</HEAD>
<BODY>
<FORM ACTION="#" NAME="convert">
Enter Text
<INPUT TYPE=TEXT NAME="originalText" ONKEYUP="document.convert.transformedText.value = transformPhrase(document.convert.originalText.value)" size="500">
<BR><BR>
Transformed Text
<INPUT TYPE=TEXT NAME="transformedText" DISABLED size="500">
</FORM>
</BODY>
</HTML>