Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
josdem committed Apr 7, 2024
2 parents 4f8c0a0 + 55a4e38 commit 34c365b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion simple-algorithms/biggest-price/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
}

def junitJupiterVersion = '5.7.0'
def junitJupiterVersion = '5.10.2'

group 'com.josdem.kata'
version '1.0-SNAPSHOT'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package com.josdem.kata;

/*
Messages with random data are coming! But we just care about prices!
Your task is to implement a function which removes all non numeric data and return just the biggest price
messages = ["hi", "2", "@#$%", "32"]
result = 32
*/

import java.util.List;
import java.util.Optional;

public class BiggestNumberFinder {

private String regex = "-?[0-9]+.?[0-9]+";

public double find(List<String> numbers) {
return numbers.stream()
.filter(it -> it.matches(regex))
.map(it -> Double.parseDouble(it))
.max(Double::compare)
.get();
}
private static final String REGEX = "-?[0-9]+.?[0-9]+";
public double find(List<String> numbers) {
Optional<Double> result = numbers.stream().filter(it -> it.matches(REGEX)).map(Double::parseDouble).max(Double::compare);
return result.orElseThrow(RuntimeException::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/*
Messages with random data are coming! But we just care about prices!
Your task is to implement a function which removes all non-numeric data and return just the biggest price
messages = ["hi", "2", "@#$%", "32"]
result = 32
*/

class BiggestNumberFinderTest {

private BiggestNumberFinder biggestNumberFinder = new BiggestNumberFinder();
private final BiggestNumberFinder biggestNumberFinder = new BiggestNumberFinder();

@Test
@DisplayName("Find biggest")
Expand Down

0 comments on commit 34c365b

Please sign in to comment.