Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions PlaylistChallenge.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
40 changes: 37 additions & 3 deletions src/main/java/io/zipcoder/Music.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
package io.zipcoder;


public class Music {

private String[] playList;

public Music(String[] playList){
public Music(String[] playList) {
this.playList = playList;
}

public Integer selection(Integer startIndex, String selection){
public Integer selection(Integer startIndex, String selection) {


int indexOfSelection = 0;

for (int i = 0; i < playList.length; i++) {

if (playList[i].equals(selection) && (playList.length - i < startIndex + i)) {
indexOfSelection += i;
}
}

//if startIndex is BEFORE the indexSelection
// [startIndex selectionIndex]

if (indexOfSelection > startIndex) {

//(left side count VS right side count)
if (indexOfSelection - startIndex < (startIndex + playList.length - indexOfSelection)) {
return indexOfSelection - startIndex;
}
return startIndex + playList.length - indexOfSelection;
}

//if startIndex is AFTER the indexSelection
// [selectionIndex startIndex]
if (indexOfSelection < startIndex) {

//(left side count VS right side count)
if (startIndex - indexOfSelection < (indexOfSelection + playList.length - startIndex)) {
return indexOfSelection + playList.length - startIndex;
}
return startIndex - indexOfSelection;
}
return null;
}
}
}
Binary file added target/classes/io/zipcoder/Music.class
Binary file not shown.
Binary file added target/test-classes/io/zipcoder/MusicTest.class
Binary file not shown.