diff --git a/src/main/java/io/zipcoder/Music.java b/src/main/java/io/zipcoder/Music.java index 180c65c..55af98d 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -9,6 +9,24 @@ public Music(String[] playList){ } public Integer selection(Integer startIndex, String selection){ - return null; + + Integer minDist = playList.length; + for(int i = 0; i < playList.length; i++){ + if(selection.equals(playList[i])){ + if(Math.abs(startIndex - i) < minDist){ + minDist = Math.abs(startIndex - i); + } + if((playList.length - Math.abs(startIndex - i)) < minDist){ + minDist = playList.length - Math.abs(startIndex - i); + } + + } + } + if(minDist == playList.length){ // song is not in playList + return -1; + } + + + return minDist; } }