Skip to main content
3 of 6
added 553 characters in body
Shaggy
  • 43.5k
  • 4
  • 36
  • 94

#Japt v2.0a0 -P, 14 bytes

f\l üv ñÊ®ÌiZÊ

Try it

f\l üv ñÊ®ÌiZÊ
                   :Implicit input of string
                   > e.g., "Kitkat Tango"

f                  :Split to an array of characters
 \l                :  Matching RegEx /[a-z]/gi
                   > ["K","i","t","k","a","t","T","a","n","g","o"]

    ü              :Sort & group (Preserves original order within each group)
     v             :  By lowercase
                   > [["a","a"],["g"],["i"],["K","k"],["n"],["o"],["t","t","T"]]

       ñ           :Sort
        Ê          :  By length
                   > [["g"],["i"],["n"],["o"],["a","a"],["K","k"],["t","t","T"]]

         ®         :Map each Z
          Ì        :  Last element of Z
                   >   ["g","i","n","o","a","k","T"]
           i       :  Prepend
            ZÊ     :    Length of Z
                   >   ["1g","1i","1n","1o","2a","2k","3T"]

                   :Implicitly join & output
                   > "1g1i1n1o2a2k3T"
Shaggy
  • 43.5k
  • 4
  • 36
  • 94