Skip to content

Instantly share code, notes, and snippets.

@rexfordkelly-at-makersquare
Forked from abalogun/W2D2 Checkpoint.js
Last active August 25, 2016 00:57
Show Gist options
  • Save rexfordkelly-at-makersquare/9c18f7d45aad476eaca98f061922993c to your computer and use it in GitHub Desktop.
Save rexfordkelly-at-makersquare/9c18f7d45aad476eaca98f061922993c to your computer and use it in GitHub Desktop.
W2D2 Checkpoint
function average(x,y) { // Good Job!, try and keep your spacing and formating consistent
return (x+y)/ 2;
}
function greeter(name) { // Good Job!
return 'Hello, '+ name;
}
function even(n) { // Good Job!
return n % 2 === 0;
}
function odd(n) { // Good Job!
return n % 2 !== 0;
}
function isPositive(n) { // Good Job!
return n >= 0;
}
function isNegative(n) { // Good Job!
return n < 0;
}
function sayHello(language) { // Good Job!, would it make any difference if you had no else statments, only if statments?
if(language === 'spanish') {
return 'Hola!';
} else if(language === 'french') {
return 'Bonjour!';
} else if(language === 'english') {
return 'Hello!';
}
}
function validCredentials(username, password) { // Good Job!
if(username.length >= 6 && password.length >= 8) {
return true;
} else {
return false;
}
}
function repeatString(str, count){
return str.repeat(count); // ok so we want to solve this without using str.repeat()
}
function average(array) { // Good Job!
var start = 0;
for(var i = 0; i < array.length; i++){
start = start + array[i];
}
return start / array.length;
}
function countWords(str) { // Good Job!
var words = str.toLowerCase().split(' ');
var hist = {};
for(var i = 0; i < words.length; i++) {
if(hist[words[i]]){
hist[words[i]]++;
} else {
hist[words[i]] = 1;
}
}
return hist;
}
function revStr(str) { // Good Job!
return str.split('').reverse().join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment