Skip to content
Open
Show file tree
Hide file tree
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
62 changes: 50 additions & 12 deletions exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,45 @@
* @return {string} reversed
* ie: "cat" => "tac"
*/

function firstReverse(str){
if (typeof str === 'string') {
return str.split('').reverse().join('')
} else {
return null;
}
}
/** Function: alphaOrder
* The function will take the str parameter being passed in and
* return the string in alphabetical order
* @param {string} str
* @return {string} in alphabetical order
* ie: "cake" => "acek"
*/

function alphaOrder(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
* return the number of vowels in the string
* @param {string} str
* @return {number} count of vowels
* ie: "oreo" => 3
*/

function vowelCount(str){
var vowels = ['a', 'e', 'i', 'o', 'u'];
if(typeof str === 'string'){
return str.split('').reduce((acc, curr) => {
(vowels.indexOf(curr.toLowerCase()) !== -1) ? acc++ : acc;
return acc;
}, 0)
} else {
return null;
}
}
/** Function: timeConvert
* The function will take the str parameter representing the amount of minutes being passed in and
* return the number of hours and minutes. Seperate the number of hours
Expand All @@ -30,7 +52,13 @@
* @return {string} as hours:minutes
* ie: 68 => 1:8
*/

function timeConvert(str){
if(typeof str === 'number'){
return `${(str / 60).toFixed(0)}:${str % 60}`;
} 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,13 +67,23 @@
* @return {string} repeated num times
* i.e repeatString("money", 3) => "moneymoneymoney".
*/

function repeatString(str, times){
if(typeof str === 'string' && typeof times === 'number'){
if(times > 0){
return str.repeat(times);
} else {
return '';
}
} else {
return null;
}
}

/**
* Below here we see a module.exports which is set to an object with a bunch of keys.
* The module.exports syntax is a built-in javascript keyword that
* allows functionality from this file to be used in other files.
* Here we are exporting an object with a bunch of keys that will reference
* allows functionality from this file to be used in other files.
* Here we are exporting an object with a bunch of keys that will reference
* the functions you have made. After you are done implementing a function,
* change the 'null' to reference the corresponding function you have just created.
* Then go into your terminal and run 'npm test' to see if the tests pass for your function.
Expand All @@ -56,9 +94,9 @@
*/

module.exports = {
firstReverse: null,
alphaOrder: null,
vowelCount: null,
timeConvert: null,
repeatString: null
firstReverse: firstReverse,
alphaOrder: alphaOrder,
vowelCount: vowelCount,
timeConvert: timeConvert,
repeatString: repeatString
}
Loading