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

116
Views
How to check whether a certain character in string comes after another character?

Given a string aaabbbcccooeellmmzzz how can I count the number of characters that comes after 'm'. For example in this case it should return 5 (i.e oozzz);

Note: Here o and z characters come after 'm' in alphabetical order not about their index position after m.

So i want to count the characters (n,o,p,q,r,s,t,u,v,w,x,y,z) as many times they appear in the string.

Sample Input : aaabbbcccooeellmmmzzz
Sample Output: 5

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use substring to remove everything from the start to the index of the last occurrence of the character, then get the length:

let character = 'm';
let str = 'aaabbbcccooeellmmmzzz';

let res = str.substring(str.lastIndexOf(character) + 1).length;
console.log(res)

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!