diff --git a/index.html b/index.html new file mode 100644 index 000000000..3d1f3f017 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + Palindrome + + + + + + \ No newline at end of file diff --git a/palindrome.js b/palindrome.js new file mode 100644 index 000000000..f53ee62b1 --- /dev/null +++ b/palindrome.js @@ -0,0 +1,90 @@ +var hacker1 = window.prompt("What is the driver\'s name\?"); +console.log("The driver's name is " + hacker1); +var hacker2 = window.prompt("What is the navigator\'s name\?"); +console.log("The navigator's name is " + hacker2); + +if (hacker1.length > hacker2.length) { + console.log("The Driver has the longest name, it has " + hacker1.length + " characters"); +} else if (hacker2.length > hacker1.length) { + console.log("Yo, navigator got the longest name, it has " + hacker2.length + " characters"); +} else { + console.log("wow, you both got equally long names, " + hacker2.length + " characters!!"); +} + +function print (name) { + var printableStr = ""; + var letter; + for (var i = 0; i < name.length; i++ ) { + letter = name[i].toUpperCase(); + printableStr+=letter; + //if the letter is the last one, no space is needed + if (i!==(name.length-1)) { + printableStr += " "; + } + } + console.log(printableStr); +} + +function reversePrint(name) { + var printableStr = ""; + var letter; + for (var i = 0; i < name.length; i++ ) { + letter = name[name.length-1-i]; + printableStr+=letter; + } + console.log(printableStr); +} + +function compare (name1, name2) { + if (name1[0]>name2[0]) { + console.log("Yo, the navigator goes first definitely"); + } else if (name1[0]= "a") && (tempStr[i] <= "z")) { + str += (tempStr[i]); + } + } + + //check if the number of characters is uneven, + //then the middle of the string is a letter + if (str.length%2===1) { + //check if letters to both sides of the middle are same + for (var i=0; i + + + + + + Sort + + + + + + diff --git a/sort.js b/sort.js new file mode 100644 index 000000000..a66995703 --- /dev/null +++ b/sort.js @@ -0,0 +1,43 @@ +function sort(arrayOfStrings) { + + if (!Array.isArray(arrayOfStrings)) { + console.log("wrong input!"); + return; + } + + for (var i=0; istring2FirstLetter) { + arrayOfStrings[j] = string2; + arrayOfStrings[j+1] = string1; + } + } + } + + console.log(arrayOfStrings); +} +sort(["qwerty", "asdfg", "zxcvb", "poiuy", "lkjhg", "mnbvc"]); + +function findLongest(arrayOfStrings) { + if (!Array.isArray(arrayOfStrings)) { + console.log("wrong input!"); + return; + } + + var longest = arrayOfStrings[0]; + + for (var i=1; i < arrayOfStrings.length; i++) { + if (arrayOfStrings[i].length>longest.length) { + longest=arrayOfStrings[i]; + } + } + console.log (longest); + return longest; +} + +findLongest(["qwerty", "asdfgtt", "zxcvbttt", "poiuytttt", "lkjhgttttt", "mnbvcttt"]); \ No newline at end of file