如以下方法所示,我不了解“比较运算符”的工作方式。如果定义的“堆栈数组”最初为空,那么如何将散列“ OPPOSITE”的元素与空数组的最后一个元素进行比较?比较是否发生在操作数“ OPPOSITE [dir]”上?即使这样,仍然不清楚。
谢谢
代码:
OPPOSITE = {
"NORTH" => "SOUTH",
"SOUTH" => "NORTH",
"EAST" => "WEST",
"WEST" => "EAST"
}
def dirReduc(arr)
stack = []
arr.each do |dir|
OPPOSITE[dir] == stack.last ? stack.pop : stack.push(dir)
end
stack
end
arr = ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]
print dirReduc(arr)
答案 0 :(得分:2)
当<Style x:Key="Collapse" TargetType="StackPanel">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=IsEnabled}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width" Duration="0:0:1" From="640" To="320"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="Expand" TargetType="StackPanel">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=IsVisible}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width" Duration="0:0:1" From="320" To="640">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
为空时,stack
将返回stack.last
。
nil
将返回OPPOSITE['NORHT']
和'SOUTH'
,如果'SOUTH' == nil
,则将评估false
分支(else
)。