Find minimum in subarray

Find index of minimum value in a subarray

Finish writing the function indexOfMinimum, which takes an array and a number startIndex, and returns the index of the smallest value that occurs with index startIndex or greater. If this smallest value occurs more than once in this range, then return the index of the leftmost occurrence within this range.

Here’s my work in Ruby:

screen-shot-2016-11-14-at-8-49-00-pm

and in js, with a while loop:

screen-shot-2016-11-14-at-9-00-37-pm

Still getting used to javascript syntax with all the semi-colons and parentheses..

Also, a note on the ‘for’ loop:

for (initializer; condition; iterator) {

    // statement(s)

}

Advertisements
Find minimum in subarray

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s