Created
August 24, 2016 04:41
-
-
Save bluebard/b1f977877bbfdfe14c778bf71605de3c to your computer and use it in GitHub Desktop.
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
/** | |
Noah Loring | |
*/ | |
// #1 | |
function average (num1, num2) { | |
return (num1 + num2)/2; | |
} | |
// #2 | |
function greeter (name) { | |
return "Welcome to Coruscant, " + name + "! Enjoy your stay."; | |
} | |
// #3 | |
function even(value) { | |
return value % 2 === 0; | |
} | |
function even(value) { | |
return value % 2 !== 0; | |
} | |
function positive(value) { | |
return value > 0; | |
} | |
function negitive(value) { | |
return value < 0; | |
} | |
// #4 | |
function sayHello (language) { | |
if (language === "zulu") { | |
return "sawubona"; | |
} | |
if (language === "balinese") { | |
return "om swasyastu"; | |
} | |
if (language === "ancient egyptian") { | |
return "liti em hotep"; | |
} | |
if (language === "klingon") { | |
return "nuqneH"; | |
} | |
return "Try again in a cooler language."; | |
} | |
// #5 | |
function validCredentials (username, password) { | |
return username.length >= 6 && password.length >= 8; | |
} | |
// #6 | |
function repeatString (str, count) { | |
return str.repeat(count); | |
} | |
// #7 | |
/** | |
I've named this function "arrayAverage" instead of "average" | |
(which is what the instructions specified) due to a function | |
above already being named "average". | |
*/ | |
function arrayAverage (array) { | |
var sum = 0; | |
for (i = 0; i < array.length; i++) { | |
sum = sum + array[i]; | |
} | |
return sum/array.length; | |
} | |
// #8 | |
/** | |
First we need to split at every " ". | |
Next we'd need a command that counts the frequency of a certain value within an array. | |
And then I'd need a loop that would build an object out of the frequencies found with the command. | |
Could be modified to be case insensitve simply by having one of the first lines within the | |
function be a .toLowerCase() command, targeting the entire arguement. | |
*/ | |
// Bonus #1 | |
/** | |
I didn't know that '.reverse' was an option, so I did it manually. The use of two variables is | |
mess, but it works. | |
*/ | |
function reverseString (str) { | |
var arr = str.split(" "); | |
var reversed = []; | |
for (i = 1; i <= arr.length; i++) { | |
reversed.push(arr[arr.length - i]); | |
} | |
return reversed.join(" "); | |
} | |
// Bonus #2 | |
/** | |
Didn't get to this one yet. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment