Skip to content

Commit 0e78f95

Browse files
committed
#21 Add more examples
1 parent a0871a4 commit 0e78f95

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/// Set of DeclarativeCOS examples.
2+
Class DeclarativeCOS.Examples Extends DeclarativeCOS.DeclarativeProvider
3+
{
4+
5+
/// Returns hex value of the passed value.
6+
///
7+
/// @Declarative("examples:toHex")
8+
ClassMethod toHex(value As %Numeric)
9+
{
10+
return $zhex(value)
11+
}
12+
13+
/// Returns $$$YES if passed value is prime number.
14+
/// Otherwise, returns $$$NO.
15+
///
16+
/// @Declarative("examples:isPrime")
17+
ClassMethod isPrime(value As %Numeric)
18+
{
19+
for i=2:1:$zsqr(value) {
20+
if (value # i = 0) {
21+
return $$$NO
22+
}
23+
}
24+
25+
return $$$YES
26+
}
27+
28+
/// Returns $$$YES if passed value is odd number.
29+
/// Otherwise, returns $$$NO.
30+
///
31+
/// @Declarative("examples:isOdd")
32+
ClassMethod isOdd(value As %Numeric)
33+
{
34+
return value # 2 '= 0
35+
}
36+
37+
/// Returns $$$YES if passed value is even number.
38+
/// Otherwise, returns $$$NO.
39+
///
40+
/// @Declarative("examples:isEven")
41+
ClassMethod isEven(value As %Numeric)
42+
{
43+
return value # 2 = 0
44+
}
45+
46+
/// Returns $$$YES if passed value is palindromic number.
47+
/// Otherwise, returns $$$NO.
48+
///
49+
/// @Declarative("examples:isPalindromic")
50+
ClassMethod isPalindromic(value As %Numeric)
51+
{
52+
return $reverse(value) = value
53+
}
54+
55+
}
56+

0 commit comments

Comments
 (0)