Exercise Thursday

Whiteboard Practice

When and how whiteboarding practice is implemented will be up to your teacher. Below is a recommended prompt.

Goal

For this week’s whiteboarding lesson, we’ll focus on using arrays and loops to assess a string.

As the interviewee:

  • Ask clarifying questions.
  • Keep talking.
  • Explain your plan at the beginning; recap what you’ve done at the end.
  • Make eye contact.
  • Plan your space.

As the interviewer:

  • Answer questions as best as you can.
  • Be encouraging. Whiteboarding is difficult!
  • Be patient. Only offer hints if your partner indicates that they need help.
  • Be engaged. Part of this practice is getting used to having someone evaluate your work as your produce it.
  • Offer constructive feedback. Find at least one thing that your partner did well and one thing they could improve at.

Problem

Prompt: Write a function that takes in an array of numbers and a number (n) and returns the array with the multiples of n removed.

Example:

  • Given: [ 1, 9, 6, 1, 3, 10, 12, 99, 2] , 3
  • Return: [ 1, 1, 10, 2 ]

Further Exploration

  • Alter your function such that it takes a third parameter called choice. If choice is "multiples", then the function should behave as normal. If choice is factors, numbers that are factors of n should be removed from the array. (i.e. Given: [ 1, 9, 6, 1, 3, 10, 12, 99, 2] , 12, "factors"; Return: [ 9, 10, 99 ]). You should create a helper function to keep your code organized.

  • Alter your function to accept an array of numbers as the second parameter. Remove the multiples/factors of each of these numbers from the original array and return the filtered array. (i.e. Given: [ 1, 9, 6, 1, 3, 10, 12, 99, 2] , [ 3, 5 ], "multiples"; Return: [ 1, 1, 99, 2 ])