通过跳过每 2 个元素来提取块的最优雅方法
Most elegant way to extract block by skipping every 2 element
假设我有
block: [a 1 b 2 c 3]
我要
[1 2 3]
像这样的东西很笨拙而且不起作用,因为我使用的是单词类型(我希望它是单词而不是字符串):
block: [a 1 b 2 c 3]
block2: []
counter: -1
foreach 'element block [
counter: negate counter
if counter append block2 element
]
EXTRACT 函数应该适合这里的要求:
>> extract/index [a 1 b 2 c 3] 2 2
== [1 2 3]
对于这种类型的东西,它相当通用。
>> help extract
USAGE:
EXTRACT series width
DESCRIPTION:
Extracts a value from a series at regular intervals.
EXTRACT is a function! value.
ARGUMENTS:
series [series!]
width [integer!] "Size of each entry (the skip)".
REFINEMENTS:
/index => Extract from an offset position.
pos [integer!] "The position".
/into => Provide an output series instead of creating a new one.
output [series!] "Output series".
假设我有
block: [a 1 b 2 c 3]
我要
[1 2 3]
像这样的东西很笨拙而且不起作用,因为我使用的是单词类型(我希望它是单词而不是字符串):
block: [a 1 b 2 c 3]
block2: []
counter: -1
foreach 'element block [
counter: negate counter
if counter append block2 element
]
EXTRACT 函数应该适合这里的要求:
>> extract/index [a 1 b 2 c 3] 2 2
== [1 2 3]
对于这种类型的东西,它相当通用。
>> help extract
USAGE:
EXTRACT series width
DESCRIPTION:
Extracts a value from a series at regular intervals.
EXTRACT is a function! value.
ARGUMENTS:
series [series!]
width [integer!] "Size of each entry (the skip)".
REFINEMENTS:
/index => Extract from an offset position.
pos [integer!] "The position".
/into => Provide an output series instead of creating a new one.
output [series!] "Output series".