From 1e5ab20176a96428b1fe2bc2bbfa36b319f3e69d Mon Sep 17 00:00:00 2001 From: josdem Date: Tue, 7 May 2024 12:18:48 -0400 Subject: [PATCH] Adding solution --- .../src/main/java/com/josdem/kata/PhoneNumberGenerator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/simple-algorithms/create-phone-number/src/main/java/com/josdem/kata/PhoneNumberGenerator.java b/simple-algorithms/create-phone-number/src/main/java/com/josdem/kata/PhoneNumberGenerator.java index b9ce156..6c6d758 100644 --- a/simple-algorithms/create-phone-number/src/main/java/com/josdem/kata/PhoneNumberGenerator.java +++ b/simple-algorithms/create-phone-number/src/main/java/com/josdem/kata/PhoneNumberGenerator.java @@ -1,9 +1,13 @@ package com.josdem.kata; import java.util.List; +import java.util.stream.Collectors; public class PhoneNumberGenerator { public String format(List numbers) { - return numbers.toString(); + StringBuilder sb = new StringBuilder(); + String numbersAsString = numbers.stream().map(String::valueOf).collect(Collectors.joining("")); + sb.append(numbersAsString).insert(0, '(').insert(4, ')').insert(5, ' ').insert(9, '-'); + return sb.toString(); } }