Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!