We use the repeat_pattern()
method to create a sequence with a pattern repeated the number of times as indicated.
With the repeat_pattern()
method, we must provide the sample pattern we want to repeat as a sequence. We’ll have to give the number of times we would like the pattern to be made. The repeat_pattern()
method will make the pattern as we intend.
repeat_pattern(pattern,count)
pattern
: This parameter is an object value that serves as the sample of the pattern we’d want to repeat as much as possible.
count
: This integer value determines how many times the pattern will be created.
For instance, if we wish to create a repeated pattern out of a variable A = {1,2,3}
which we want to repeat five times. Using the repeat_pattern()
method, we’ll get an outcome such as: {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3}
.
This function will return a sequence containing a repeated pattern. The length of the returned sequence is obtained by multiplying the count by the length of the pattern.
length = count*length(pattern)
If the method fails due to the wrong pattern
parameter, it will return an empty sequence.
Let’s see the code below on how to use the repeat_pattern()
method.
include std/sequence.esequence pattern = {1,2,3}sequence pat = "This day"sequence output1, output2output1 = repeat_pattern(pat,4)output2 = repeat_pattern(pattern,4)printf(1,"\n%s\n",{output1})print(1,output2)
sequence.e
module.repeat_pattern()
method to create a pattern.