From 76104a7181c31d3c7bcc09e1d83db209625fdbdf Mon Sep 17 00:00:00 2001 From: michael-doll Date: Sun, 27 Oct 2019 10:56:15 -0400 Subject: [PATCH] save work, passes tests, re evaluate solution --- src/main/java/io/zipcoder/Music.java | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/zipcoder/Music.java b/src/main/java/io/zipcoder/Music.java index 180c65c..3fcd20e 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -1,5 +1,7 @@ package io.zipcoder; - +//Michael Doll +//10.27.19 +//Need to re evaluate public class Music { private String[] playList; @@ -8,7 +10,33 @@ public Music(String[] playList){ this.playList = playList; } - public Integer selection(Integer startIndex, String selection){ - return null; + public Integer selection(Integer startIndex, String selection) { + int shortest = 0; + int count = 0; + for (int i = startIndex; i < playList.length; i++) { + if (playList[i].equals(selection)) { + shortest = count; + break; + } + if (i == playList.length - 1 && selection.equals(playList[0])) { + count++; + shortest = count; + } + count++; + } + count = 0; + for (int i = startIndex; i >=0; i--) { + if (playList[i].equals(selection)) { + if (count < shortest) { + shortest = count; + break; + } + } + count++; + if (i == 0 && selection.equals(playList[playList.length-1])) { + shortest = count; + } + } + return shortest; } }