# Algorithms…Again

Tiffany White,

function truncateString(str, num) { // Clear out that junk in your trunk

// If str is greater than num // if it is longer than the given maximum string length // or str.length // slice/truncate the value of str, whatever it is // and add (...) to the end of the sliced/truncated //string. This adds to the truncated string // if num is less than three // than the addition of the (...) does not add to the // truncated string // use the length property on a variable that references str // what is num? // what is str? // truncateString("A-tisket a-tasket A green and yellow basket"<---str, 11<---num); // what is the maximum string length? (the second argument 'num' is the maximum string // length)

/* Don't look at the function below and hard code the solution into your logic. use the variables and values here. use conditionals to test if a condition is true. use a for loop to count. use a nested if/else to test complex conditions. use nested for loops */

var str1 = str.length; var str2 = num.length;

if (str1 > str2) { return str.slice(str1) + "..."; } else if (str2 < 3) { return str.slice(str1); } return str; }

function truncateString(str, num) { // Clear out that junk in your trunk

// If str is greater than num // if it is longer than the given maximum string length // or str.length // slice/truncate the value of str, whatever it is // and add (...) to the end of the sliced/truncated //string. This adds to the truncated string // if num is less than three // than the addition of the (...) does not add to the // truncated string // use the length property on a variable that references str // what is num? // what is str? // truncateString("A-tisket a-tasket A green and yellow basket"<---str, 11<---num); // what is the maximum string length? (the second argument 'num' is the maximum string // length)

/* Don't look at the function below and hard code the solution into your logic. use the variables and values here. use conditionals to test if a condition is true. use a for loop to count. use a nested if/else to test complex conditions. use nested for loops */

var str1 = str.length; var str2 = num.length;

if (str1 > str2) { return str.slice(str1) + "..."; } else if (str2 < 3) { return str.slice(str1); } return str; }