Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
How to create a function that tells you which part of a fence remains uncolored?

I need help to understand how const colorIntervals can receive two arguments as a callback (as it shows at the end).

The task is to implement the function colorFence(length), where length is the total length of the fence. This function should return another function which can be called with arguments left and right, where 0 ≤ left ≤ right < length. The returned function colors the segment of the fence from left to right (inclusive) into the black color, and returns the remaining total length of the white fence.

An example of interaction is as follows:

const colorIntervals = colorFence(20);

colorIntervals(18, 18); // The remaining length of the white fence is 19.
colorIntervals(0, 3); // The remaining length of the white fence is 15.
colorIntervals(17, 19); // The remaining length of the white fence is 13 (since segment 18 was already painted).
colorIntervals(0, 19); // The remaining length of the white fence is 0.
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your question precisely describes what you need to do:

  1. create a function colorFence
  • arguments: length
  • return: another function
  1. create another function
  • arguments: left, right
  • return 0 <= left <= right < left

Below you find a pseudo code skeleton. Try to adapt this requirements into the pseudo code.

function first(a) {
  console.log("first", a)
  return second
}

function second(b, c) {
  console.log("second", b, c)
}

const firstFunctionExecution = first(1)
firstFunctionExecution(2, 3)
firstFunctionExecution(4, 5)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda