Skip to content

Instantly share code, notes, and snippets.

@abalogun
Created August 24, 2016 05:51
Show Gist options
  • Save abalogun/bc6b83bdd02e5b361fee79edd5cb83c7 to your computer and use it in GitHub Desktop.
Save abalogun/bc6b83bdd02e5b361fee79edd5cb83c7 to your computer and use it in GitHub Desktop.
W2D2 Checkpoint
function average(x,y) {
return (x+y)/ 2;
}
function greeter(name) {
return 'Hello, '+ name;
}
function even(n) {
return n % 2 === 0;
}
function odd(n) {
return n % 2 !== 0;
}
function isPositive(n) {
return n >= 0;
}
function isNegative(n) {
return n < 0;
}
function sayHello(language) {
if(language === 'spanish') {
return 'Hola!';
} else if(language === 'french') {
return 'Bonjour!';
} else if(language === 'english') {
return 'Hello!';
}
}
function validCredentials(username, password) {
if(username.length >= 6 && password.length >= 8) {
return true;
} else {
return false;
}
}
function repeatString(str, count){
return str.repeat(count);
}
function average(array) {
var start = 0;
for(var i = 0; i < array.length; i++){
start = start + array[i];
}
return start / array.length;
}
function countWords(str) {
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) {
return str.split('').reverse().join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment