From: Logan C. [mailto:[email protected]]
I’ve edited out some false starts. Please feel free to point
out any flaws
that I’ve missed
Abbrev.abbrev(items).sort_by { |s,| s.length }.first.first[0…-2]
I cannot prove it wrong, hacker Logan
i just put some cosmetics though by getting the extract fr min,
irb(main):099:0> list=[
irb(main)1* “item two of those”,
irb(main):101:1* “item two”,
irb(main):102:1* “item1”,
irb(main):103:1* “item22”,
irb(main):104:1* “item333”,
irb(main):105:1* “item 444”,
irb(main):106:1* “item 5555”,
irb(main):107:1* “item6a”,
irb(main):108:1* “item6b”,
irb(main):109:1* “item—x”,
irb(main):110:1* “itemy”,
irb(main):111:1* “item whatever :)”,
irb(main):112:1* ]
=> [“item two of those”, “item two”, “item1”, “item22”, “item333”, “item
444”, “item 5555”, “item6a”, “item6b”, “item—x”, “itemy”, “item
whatever :)”]
irb(main):113:0>
list.abbrev.min{|(a1,),(b1,)|a1.length<=>b1.length}.first[0…-2]
=> “item”
so,
list.abbrev.min{|(a1,),(b1,)|a1.length<=>b1.length}.first[0…-2]
your magic number “0…2” is an amazingly simple hack (it looks like 42
:). but i’m not sure how this abbrev scheme stands stands against the
regex solutions though.
kind regards -botp