Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda