Skip to content

Commit 29cbde0

Browse files
committed
Restore DigitalRoot legacy API compatibility
1 parent abd8055 commit 29cbde0

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/main/java/kyu6/DigitalRoot.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ public static int digitalRoot(int n) {
2828
return result;
2929
}
3030

31+
/**
32+
* Retains compatibility with the original Codewars API.
33+
*
34+
* @param n a non-negative integer
35+
* @return the digital root of {@code n}
36+
* @deprecated use {@link #digitalRoot(int)} instead
37+
*/
38+
@Deprecated
39+
public static int digital_root(int n) {
40+
return digitalRoot(n);
41+
}
42+
3143
/**
3244
* Digital root is the recursive sum of all the digits in a number.
3345
* Given n, take the sum of the digits of n. If that value has more than one

src/test/java/kyu6/DigitalRootTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ class DigitalRootTest {
2121
void shouldReduceNumberToSingleDigit(int value, int expected) {
2222
assertEquals(expected, DigitalRoot.digitalRoot(value));
2323
assertEquals(expected, DigitalRoot.digitalRootRecursiveStream(value));
24+
assertEquals(expected, DigitalRoot.digital_root(value));
2425
}
2526
}

0 commit comments

Comments
 (0)