Perl 6中多个针的指数

时间:2018-05-11 21:11:45

标签: search perl6

我希望在单词中找到indices多个字母。我不想使用Regex es,因为它们会减慢程序速度(已经比我想要的慢)。

> "banana".indices(("a", "b").any)
any((1 3 5), (0))

我怎样才能获得0, 1, 3, 5

3 个答案:

答案 0 :(得分:9)

我会选择这样的东西(在REPL中):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <div class="col-sm-3">
        first text here
      </div>
      <div class="col-sm-2">
        THIS ONE I NEED TO SET "COL-SM-1.5" to give more space for next div
      </div>
      <div class="col-sm-5">
        third text here
      </div>
      <div class="col-sm-1">
        forth text here
      </div>
      <div class="col-sm-1">
        forth text here
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:8)

> "banana".comb.grep: 'a' | 'b',:k
(0 1 3 5)

我不知道comb在这种情况下是否使用regex

gather for 'banana'.comb.antipairs  {.value.take if .key ∈ ['a','b'] } 

# or
gather 'banana'.comb.antipairs».&{.value.take if .key ∈ ['a','b'] }  

答案 2 :(得分:7)

我的解决方案是:

onItemSelected

基本上,循环遍历要查找的所有字母(> <a b>.map( { |"banana".indices($_) } ).sort (0 1 3 5) )并将这些字母映射到其索引(<a b>.map),然后滑动找到的索引("banana".indices($_))并对结果进行排序(|)。