From ebdecfb12aa83dabf71378c55b14ae47ab0f20ce Mon Sep 17 00:00:00 2001 From: KrishnaP Date: Wed, 27 Dec 2017 15:15:16 -0800 Subject: [PATCH] Work was done but had computer troubles --- exercises.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/exercises.js b/exercises.js index 25ed379..27ad6a2 100644 --- a/exercises.js +++ b/exercises.js @@ -5,6 +5,13 @@ * @return {string} reversed * ie: "cat" => "tac" */ +var firstReverse = function(str){ + if(typeof str != 'string'){ + return null; + } + else + return str.split('').reverse().join(''); +}; /** Function: alphaOrder * The function will take the str parameter being passed in and @@ -13,6 +20,13 @@ * @return {string} in alphabetical order * ie: "cake" => "acek" */ +var alphaOrder = function(str){ + if(typeof str === 'string'){ + return str.split('').sort().join(''); + } + else + return null +} /** Function: vowelCount * The function will take the str parameter being passed in and @@ -21,6 +35,22 @@ * @return {number} count of vowels * ie: "oreo" => 3 */ +var vowelCount = function(str){ + var vowels = ['a','e','i','o','u']; + var count = 0; + + if(typeof str !== 'string'){ + return null; + } + + for(var i = 0; i< str.length; i++){ + + if(vowels.includes(str[i])){ + count++ + } +} + return count; +} /** Function: timeConvert * The function will take the str parameter representing the amount of minutes being passed in and @@ -31,6 +61,16 @@ * ie: 68 => 1:8 */ + var timeConvert = function(num){ + var minutes = num%60; + var hours = Math.floor(num/60); + + if(typeof num === 'number') + return hours + ':' + minutes; + else + return null; + } + /** Function: repeatString * The function will take in two parameters and repeat a given string (first argument) * num times (second argument). Return an empty string if num is a negative number @@ -39,7 +79,15 @@ * @return {string} repeated num times * i.e repeatString("money", 3) => "moneymoneymoney". */ +var repeatString = function(str,num){ + if(num > 0){ + return str.repeat(num); + } + else + return null; + +} /** * Below here we see a module.exports which is set to an object with a bunch of keys. @@ -56,9 +104,9 @@ */ module.exports = { - firstReverse: null, - alphaOrder: null, - vowelCount: null, - timeConvert: null, - repeatString: null + firstReverse: firstReverse, + alphaOrder: alphaOrder, + vowelCount: vowelCount, + timeConvert: timeConvert, + repeatString: repeatString }