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

173
Views
How can I get the kth permutation repeated letter (codewars challenge)

I'm struggling with kata called permutation by number by giving an input a word and number (k) the task is returning the kth permutation , actually my function support the unique exp( the 99th permutation of ACGIM = MAGIC) letters how can I enhance it to support the non-repeated letters?

function permutationByNumber(str,index) {  
  let  strr = str.split('').sort().join('')
  function fac(integ){
  //  i made this factorial function to get all  factorial numbers  
   if(integ==1)  return   1
    return  integ*fac(integ-1) }  
 let index1
 let index2 
 let  result =[]
 let l = strr.length
 function getpermutation(strr,index){
   if(result.length==l-1){
     return result.push(strr)}
    index1=Math.floor(index/fac(strr.length-1))
    index2=Math.floor(index%fac(strr.length-1))
    result.push(strr[index1])
    strr=strr.slice(0,index1)+strr.slice(index1+1)
    getpermutation(strr,index2)
 }
 getpermutation(strr,index)
return result.join('')
 
}
   console.log(permutationByNumber("ACGIM",99))
about 4 years ago · Juan Pablo Isaza
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!