diff --git a/PlaylistChallenge.iml b/PlaylistChallenge.iml index 54ddd53..6098888 100644 --- a/PlaylistChallenge.iml +++ b/PlaylistChallenge.iml @@ -13,5 +13,9 @@ + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index bbd82c1..cd17122 100644 --- a/pom.xml +++ b/pom.xml @@ -16,5 +16,10 @@ 4.12 test + + junit + junit + RELEASE + \ No newline at end of file diff --git a/src/main/java/io/zipcoder/Music.java b/src/main/java/io/zipcoder/Music.java index 180c65c..14d1e86 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -1,14 +1,48 @@ package io.zipcoder; + public class Music { private String[] playList; - public Music(String[] playList){ + public Music(String[] playList) { this.playList = playList; } - public Integer selection(Integer startIndex, String selection){ + public Integer selection(Integer startIndex, String selection) { + + + int indexOfSelection = 0; + + for (int i = 0; i < playList.length; i++) { + + if (playList[i].equals(selection) && (playList.length - i < startIndex + i)) { + indexOfSelection += i; + } + } + + //if startIndex is BEFORE the indexSelection + // [startIndex selectionIndex] + + if (indexOfSelection > startIndex) { + + //(left side count VS right side count) + if (indexOfSelection - startIndex < (startIndex + playList.length - indexOfSelection)) { + return indexOfSelection - startIndex; + } + return startIndex + playList.length - indexOfSelection; + } + + //if startIndex is AFTER the indexSelection + // [selectionIndex startIndex] + if (indexOfSelection < startIndex) { + + //(left side count VS right side count) + if (startIndex - indexOfSelection < (indexOfSelection + playList.length - startIndex)) { + return indexOfSelection + playList.length - startIndex; + } + return startIndex - indexOfSelection; + } return null; } -} +} \ No newline at end of file diff --git a/target/classes/io/zipcoder/Music.class b/target/classes/io/zipcoder/Music.class new file mode 100644 index 0000000..fa34923 Binary files /dev/null and b/target/classes/io/zipcoder/Music.class differ diff --git a/target/test-classes/io/zipcoder/MusicTest.class b/target/test-classes/io/zipcoder/MusicTest.class new file mode 100644 index 0000000..3a5845d Binary files /dev/null and b/target/test-classes/io/zipcoder/MusicTest.class differ