Permalink
Browse files

version 1.0 - everything works. nothing is done w/ the final arrays o…

…utside of dumping them onto the screen at the end of processing. array is handled through a spearate file.
  • Loading branch information...
binaryorganic committed Jun 21, 2011
1 parent 3b74f27 commit 933e042e2da0c6854ae9c91db5eb76594979b00c
Showing with 52 additions and 116 deletions.
  1. +4 −13 index.html
  2. +48 −103 onehanded.js
View
@@ -1,30 +1,21 @@
-
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
+<title>onehanded.js</title>
-<title>Title Goes Here</title>
-
-<script type="text/javascript" src="wordlist-sample.js"></script>
+<script type="text/javascript" src="wordlist.js"></script>
<script type="text/javascript" src="onehanded.js"></script>
</head>
<body>
-<button onclick="debug1()">cycle through word list</button>
-<button onclick="debug2()">cycle through letters of first word</button>
-<button onclick="debug3()">tell me if 3rd word is right-handed</button>
-<button onclick="debug4()">test nested while loops</button>
-<button onclick="debug5()">debug the main function</button>
-
-<span id="debug"><p></p></span>
-
-<script>document.getElementById("debug").firstChild.nodeValue = word;</script>
+<button onclick="oneHanded()">run.</button>
+<script> </script>
</body>
View
@@ -1,145 +1,90 @@
-/*
-
- Basic flowchart of what's needed:
-- an array of words to parse through
-- an array for both left and right handed letters
-- loop #1 to pull a word from the dictionary and run loop #2 and #3
-- loop #2 to pull a letter from the word selected by loop #1
-- lopp #3 to cycle each letter pulled by loop #3 through a comparison of each value in the handedness arrays
-
- Also, it just occured to me that maybe we just need one handedness array?
- If we only check say, the right hand (because it's shorter), three things
- are possible. 1-every character is a match (a right-handed word) 2-some
- characters are a match (a two-handed word) or 3-no characters match (a
- left-handed word).
-
- Thoughts?
-
-*/
-var word = 0;
- isLeft = false;
- isRight = false;
- isBoth = false;
-
+var word = 0;
+var leftHanded = [];
+var rightHanded = [];
+var bothHanded = [];
// build handedness arrays
-var left = ["q", "w", "e", "r", "t", "a", "s", "d", "f", "g", "z", "x", "c", "v", "b"]; //left-handed letters
-var right = ["m", "n", "h", "j", "k", "l", "p", "o", "i", "u", "y", "b"]; //right-handed letters
-
-/* we need to make a decision one way or the other for handling of "b"
-It's present at the end of both arrays at the moment. For that to work,
-we need to write the verification function to not cross-reference the
-other array. It should be enough to say that if every letter exists in
-one array or the other we've got a match, so this shouldn't be a problem.
-The other option would be to leave "b" out of both and just skip it
-through an else statement or something, but I think it's fine as it. */
-
-//CYCLING THROUGH THE WORD LIST
-
-function debug1() {
-
- var i = 0;
- while (i < wordlist.length) {
- selectedWord = wordlist[i];
- alert(selectedWord);
- i++;
- }
-}
+var left = ["q", "w", "e", "r", "t", "a", "s", "d", "f", "g", "z", "x", "c", "v", "b"];
+var right = ["m", "n", "h", "j", "k", "l", "p", "o", "i", "u", "y"];
-//CYCLING THROUGH EACH LETTER OF THE SELECTED WORD
+// main function
+function oneHanded() {
-function debug2() {
+ word = 0; // start with the first word
+
+ while (word < wordlist.length) {
+
+ //reset for each new word
+ isLeft = false;
+ isRight = false;
+ isBoth = false;
+
+ loop1(); // send word to the loop for proceessing
+
+ // handedness has already been determined when we get back here. send it for storage!
+ if (isRight == true && isLeft == false) {
+ rightHanded.push(wordlist[word]);
+ }
- var i = 0;
- var selectedWord = wordlist[0];
- while (i < selectedWord.length) {
- alert(selectedWord.substr(i,1));
- i++
+ else if (isRight == false && isLeft == true) {
+ leftHanded.push(wordlist[word]);
+ }
+
+ else {
+ bothHanded.push(wordlist[word]);
+ }
+
+ word++
}
-}
-
-//mmmmm... just gonna try to write the whole thing here and see what happens...
-
-function debug3() { // First Loop: pull a word and send it to the second loop. We'll keep doing this until we've gone through all the words in the array
+// print results (temporary)
+dumpLeft();
+dumpRight();
- word = 0;
-
- while (word < wordlist.length) {
- loop2();
- word++
- }
}
-function loop2() { // Second Loop: pull a letter from each word and send it to loop 3.
+function loop1() { // pull a letter from each word and send it to loop 2.
letter = 0;
while (letter < wordlist[word].length) {
- loop3();
- letter++
+ loop2();
+ letter++
}
}
-function loop3() { // Third Loop: compare pulled letter to each letter in the right-handed array
+function loop2() { // pull a letter from the handedness arrays and send it and the checking letter for compaison
handCheck = 0;
- while (handCheck < right.length) {
+ while (handCheck < left.length) {
compare();
handCheck++
}
}
-function compare() { // Where we actually check each letter against the right-handed array and (for now) set a variable that tells us what hand a word is
-
-
+function compare() { // Check each letter for handedness
if (wordlist[word].substr(letter, 1) == right[handCheck]) {
-
isRight = true;
}
- else {
+
+ else if (wordlist[word].substr(letter, 1) == left[handCheck]) {
isLeft = true;
}
-}
-
-function debug5() { //debugging the above functions
- alert(wordlist[word].substr(letter, 1));
- alert(right.substr[handCheck](1, 1));
}
-
-
-
-
-
-//BEGIN NESTED WHILE LOOP TEST
-
-function debug4() {
-
- i = 0;
- n = 0;
- while (i < 10) {
- nestedLoop();
- alert('i='+i)
- i++
- n = 0;
- }
+//just a quick way to print the results on screen for now
+function dumpLeft() {
+document.write(leftHanded + '<br />');
}
-function nestedLoop(){
- while (n <3) {
- alert('n='+n);
- n++
- }
+function dumpRight() {
+document.write(rightHanded);
}
-//END NESTED WHILE LOOP TEST (SUCCESS!)
-
-

0 comments on commit 933e042

Please sign in to comment.