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

174
Visualizações
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
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