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 1: Write a method that takes in an array of numbers and returns an array with all number whose digits add up to an even number removed. The sum of the digits for 13 is 4, so it would be removed. The sum of the digits for 124 is 7, so it would not be removed.

Example:

  • Given: [ 1001, 93, 625, 1, 43, 10, 12, 99, 200]
  • Return: [ 625, 1, 43, 10, 12 ]

Prompt 2: Write a method 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

Prompt 1:

  • Alter your method such that it takes a second parameter called choice. If choice is "true", then the method should behave as normal. If choice is false, then numbers whose digets sun to an odd number should be removed.
  • Alter your method such that it takes a second parameter (n) of type number. The method should filter the input array to remove all numbers whose digits add up to n.

Prompt 2:

  • Alter your method such that it takes a third parameter called choice. If choice is "multiples", then the method 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 method to keep your code organized.

  • Alter your method 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 ])