From b5ff84d65f4c10041157fefd1d9b0f541b6aa76b Mon Sep 17 00:00:00 2001 From: robertgordon Date: Wed, 29 May 2019 15:26:34 -0400 Subject: [PATCH] method appears functional --- src/main/java/io/zipcoder/Music.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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; } }