-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimplePigLatin.java
More file actions
33 lines (26 loc) · 854 Bytes
/
SimplePigLatin.java
File metadata and controls
33 lines (26 loc) · 854 Bytes
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
package com.smlnskgmail.jaman.codewarsjava.kyu5;
import java.util.Arrays;
import java.util.stream.Collectors;
// https://www.codewars.com/kata/520b9d2ad5c005041100000f
public class SimplePigLatin {
private final String input;
public SimplePigLatin(String input) {
this.input = input;
}
public String solution() {
return Arrays
.stream(input.split(" "))
.map(this::pigLatinWord)
.collect(Collectors.joining(" "));
}
private String pigLatinWord(String word) {
if (word.length() == 0) {
return "";
}
char firstSymbol = word.charAt(0);
if (word.length() == 1 && !Character.isLetter(firstSymbol)) {
return String.valueOf(firstSymbol);
}
return word.substring(1) + firstSymbol + "ay";
}
}