Pregunta de entrevista de WePay

Generic JS algorithm problem solving challenge.