-
-
Save rexfordkelly-at-makersquare/ff3eb416930d773026e1a9b252951e2b 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) { // Good Job! | |
return (num1 + num2)/2; | |
} | |
// #2 | |
function greeter (name) { // Good Job! | |
return "Welcome to Coruscant, " + name + "! Enjoy your stay."; | |
} | |
// #3 | |
function even(value) { // Good Job! | |
return value % 2 === 0; | |
} | |
function even(value) { // Good Job! | |
return value % 2 !== 0; | |
} | |
function positive(value) { // Good Job! | |
return value > 0; | |
} | |
function negitive(value) { // Good Job! | |
return value < 0; | |
} | |
// #4 | |
function sayHello (language) { // Good Job! | |
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) { // Good Job! | |
return username.length >= 6 && password.length >= 8; | |
} | |
// #6 | |
function repeatString (str, count) { // Good Job! | |
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) { // Good Job! | |
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) { // Good Job! | |
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