Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 53 additions & 5 deletions exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
}