Skip to content

Instantly share code, notes, and snippets.

@SnoopSqueak
Last active November 23, 2017 17:17
Show Gist options
  • Select an option

  • Save SnoopSqueak/2fbc5f3169fe3030e6d6b4ca2e4dae66 to your computer and use it in GitHub Desktop.

Select an option

Save SnoopSqueak/2fbc5f3169fe3030e6d6b4ca2e4dae66 to your computer and use it in GitHub Desktop.

For each problem, copy the code to a JS Bin. The only tabs needed are Javascript and Console. Try to complete the entire program before hitting "run" to check your work.

1.

// Write a function above these comments called
//  "processReplies" which takes in an array of
//  comments (strings). For each comment, if it
//  is longer than 10 characters, log "Approved"
//  to the console. Otherwise, log "Rejected".

// Should log:
//   "Approved"
//   "Rejected"
//   "Approved"
//   "Rejected"
//   "Rejected"
console.log("Processing feedback for nostalgic cash grab...");
processReplies(["I had a terrible time", "boo", "Worst movie I've ever seen", "", "trash"]);

// Should log:
//   "Rejected"
//   "Approved"
//   "Rejected"
//   "Approved"
//   "Approved"
console.log("Processing feedback for other nostalgic cash grab...");
processReplies(["Wow!", "What a great show", "#win", "instant classic", "I can never watch another movie again"]);

// Should log:
//   "Approved"
//   "Rejected"
//   "Rejected"
//   "Approved"
//   "Rejected"
console.log("Processing feedback from experiment 2A...");
processReplies(["Movin' pictures?!", "Ah!", "A witch!", "Burn them at the stake!", "Burn!"]);

2.

// Write a function "isInArray" above these comments that
//   takes in an array of strings, and a single string,
//   and returns true if the single string is in the
//   array or false if it is not.
//
// Should print true
console.log(isInArray(["cat", "dog", "elephant", "frog", "goat"], "cat"));
// Should print false 
console.log(isInArray(["cat", "dog", "elephant", "frog", "goat"], "bat"));
// true
console.log(isInArray(["cat", "dog", "elephant", "frog", "goat"], "goat"));
// false
console.log(isInArray(["cat", "dog", "elephant", "frog", "goat"], "donkey"));

3.

// Write a function "totalCharCount" above these comments
//   that takes in an array of strings and returns the
//   total character count from all of the strings added
//   together.
//
// Should log 3
console.log(totalCharCount(["1", "2", "3"]));
// Should log 15
console.log(totalCharCount(["Hello", "dear", "friend"]));
// Should log 39
console.log(totalCharCount(["It", "was", "the", "best", "of", "times", "it", "was", "the", "worst", "of", "times"]));
// Should log 0
console.log(totalCharCount([""]));
// Should log 0
console.log(totalCharCount(["", "", ""]));

4.

// Write a function above these comments called
//   "areArrayLengthsEqual" that takes in an array
//   of arrays. If each of these sub-arrays has
//   the same length, return true; if any two of
//   them have different lengths, return false.
//
// Should return true
console.log(areArrayLengthsEqual([
  [0, 1, 2, 3, 4],
  ["zero", "one", "two", "three", "four"]
]));
// Should return true:
console.log(areArrayLengthsEqual([
  ["blah", "blah", "blah"],
  [0, 1, 2],
  [null, null, null]
]));
// Should return false:
console.log(areArrayLengthsEqual([
  [5, 4, 3, 2, 1],
  [0, 1, 2, 3, 4],
  ["zero", "one", "two", "three", "four", "five"]
]));
// Should return false:
console.log(areArrayLengthsEqual([
  [0, 1, 2, 3, 4],
  ["singularity"]
]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment