diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..f3891de --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4361200 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5103107 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PlaylistChallenge.iml b/PlaylistChallenge.iml new file mode 100644 index 0000000..4e3316b --- /dev/null +++ b/PlaylistChallenge.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index bbd82c1..746fa88 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder PlaylistChallenge 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + diff --git a/src/main/java/io/zipcoder/Music.java b/src/main/java/io/zipcoder/Music.java index 180c65c..c88aa83 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -4,11 +4,33 @@ public class Music { private String[] playList; - public Music(String[] playList){ + public Music(String[] playList) { this.playList = playList; } - public Integer selection(Integer startIndex, String selection){ - return null; +// String[] playlist = {"dancinginthedark","rio","liveoak","liveoak"}; +// Music music = new Music(playlist); +// Integer startingIndex = 0; +// String selection = "liveoak"; +// Integer expected = 1; +// Integer actual = music.selection(startingIndex, selection); +// Assert.assertEquals(expected, actual); + +// def distance(len_my_list, idx_1, idx_2): +// dist = abs(idx_1 - idx_2) +// return min(len_my_list - dist, dist) + public Integer selection(Integer startIndex, String selection) { + int current = 0; + + + for (int i = 0; i < playList.length; i++) { + if (playList[i].equals(selection)) { + current = Math.abs(startIndex - i); + + } + } + + + return Integer.min(playList.length - current, current); } } diff --git a/target/classes/io/zipcoder/Music.class b/target/classes/io/zipcoder/Music.class new file mode 100644 index 0000000..6f84586 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..b23c799 Binary files /dev/null and b/target/test-classes/io/zipcoder/MusicTest.class differ