-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
16 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
simple-algorithms/biggest-price/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
23 changes: 6 additions & 17 deletions
23
simple-algorithms/biggest-price/src/main/java/com/josdem/kata/BiggestNumberFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters