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

134
Views
Creating a function that returns a function with individual letters

Trying to create a function that returns a function and returned function will provide the individual characters of the string passed to the original function on its invocations. When the end of the string is met, it will start back at the beginning.

Example: 'cat' should return: 'c' (on the first invocation) 'a' (on the second invocation) 't' (on the third) 'c' (should then return back to beginning)

Here is the code that I have thus far:

function individualChar (str) {
let individualStr = str;
let invoked = 0;
return function () {
    if (invoked > 0) {
        let char = individualStr.slice(0);
        invoked++
        return `${char}`;
    }
    return individualStr;
}

}

My thought process was having the individualStr assigned to the str argument along with creating an 'invoked' counter. Then in the returned function, creating the 'char' variable and assigning that to the individualStr and slice it at the first character (0), to take it out, and then have an invoke counter to invoke the function as needed.

However, as of right now, it's still only returning the entire string.

I thought about maybe using a while loop as well, to keep track of the number of invocations, but I wasn't sure if that would be best approach for this.

Any guidance would be appreciated!

about 4 years ago · Santiago Gelvez
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!