-
Notifications
You must be signed in to change notification settings - Fork 1
/
funciones.xq
154 lines (139 loc) · 2.99 KB
/
funciones.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
(: contar los ítems :)
let $items := (1,2,3,4,5,6)
let $count := count($items)
return
<result>
<count>{$count}</count>
</result>,
(: sumar los ítems :)
let $items := (1,2,3,4,5,6)
let $sum := sum($items)
return
<result>
<sum>{$sum}</sum>
</result>,
(: calcular el promedio :)
let $items := (1,2,3,4,5,6)
let $avg := avg($items)
return
<result>
<avg>{$avg}</avg>
</result>,
(: hallar el mínimo :)
let $items := (1,2,3,4,5,6)
let $min := min($items)
return
<result>
<min>{$min}</min>
</result>,
(: hallar el máximo :)
let $items := (1,2,3,4,5,6)
let $max := max($items)
return
<result>
<max>{$max}</max>
</result>,
(: listar los valores distintos :)
let $items := (1,2,4,4,5,5)
let $unique-items := distinct-values($items)
return
<result>
<items>
{
for $item in $unique-items
return <item>{$item}</item>
}
</items>
</result>,
(: listar la subsecuencia entre 2 y 4 inclusive :)
let $items := (1,2,3,4,5,6)
let $sub-items := subsequence($items,2,4)
return
<result>
<items>
{
for $item in $sub-items
return <item>{$item}</item>
}
</items>
</result>,
(: insertar antes del sexto elemento :)
let $items := (1,2,3,4,5,9)
let $additional-items := (6,7,8)
let $new-items := insert-before($items,6,$additional-items)
return
<result>
<items>
{
for $item in $new-items
return <item>{$item}</item>
}
</items>
</result>,
(: eliminar el cuarto elemento :)
let $items := (1,2,3,4,5,6)
let $new-items := remove($items,4)
return
<result>
<items>
{
for $item in $new-items
return <item>{$item}</item>
}
</items>
</result>,
(: listar en reversa :)
let $items := (1,2,3,4,5,6)
let $new-items := reverse($items)
return
<result>
<items>
{
for $item in $new-items
return <item>{$item}</item>
}
</items>
</result>,
(: hallar el cuarto elemento :)
let $items := (1,2,3,4,5,6)
let $indexOf := index-of($items,4)
return
<result>
<indexof>{$indexOf}</indexof>
</result>,
(: hallar el último elemento :)
let $items := (1,2,3,4,5,6)
let $lastElement := $items[last()]
return
<result>
<lastElement>{$lastElement}</lastElement>
</result>,
(: listar las posiciones de los impares :)
let $items := (1,2,3,4,5,6)
return
<result>
<items>
{
for $item in $items[position() mod 2 eq 1]
return <item>{$item}</item>
}
</items>
</result>,
(: mostrar la fecha del sistema :)
let $date := current-date()
return
<results>
<date>{$date}</date>
</results>,
(: listar la hora del sistema :)
let $time := current-time()
return
<results>
<time>{$time}</time>
</results>,
(: listar la fecha y hora del sistema :)
let $datetime := current-dateTime()
return
<results>
<datetime>{$datetime}</datetime>
</results>