diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..2bb69ef --- /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..d30d09e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ 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..0ddf51c --- /dev/null +++ b/PlaylistChallenge.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ 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..f83f4b2 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -1,5 +1,7 @@ package io.zipcoder; +import java.util.Arrays; + public class Music { private String[] playList; @@ -9,6 +11,57 @@ public Music(String[] playList){ } public Integer selection(Integer startIndex, String selection){ - return null; + + String[] upButton = new String[playList.length]; + String[] downButton = new String[playList.length]; + + + // build downButton array + + int w = 0; + for (int i = startIndex; i < playList.length; i++){ + downButton[w] = playList[i]; + w++; + } + + //int w = playList.length - startIndex; + + for (int i = 0; w < playList.length; i++) { + downButton[w] = playList[i]; + w++; + } + + + + // build upButton array + + int x = 0; + for (int j = startIndex; j >= 0; j--){ + upButton[x] = playList[j]; + x++; + } + + for(int j = playList.length -1; j > startIndex; j--){ + upButton[x] = playList[j]; + x++; + } + + //print arrays + /* + System.out.println(Arrays.toString(upButton)); + System.out.println(Arrays.toString(downButton)); + */ + + //test which index is lower + + int ans; + + if(Arrays.asList(downButton).indexOf(selection) <= Arrays.asList(upButton).indexOf(selection)){ + ans = Arrays.asList(downButton).indexOf(selection); + } else { + ans = Arrays.asList(upButton).indexOf(selection); + } + + return ans; } } diff --git a/target/classes/io/zipcoder/Music.class b/target/classes/io/zipcoder/Music.class new file mode 100644 index 0000000..edee04f 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