@@ 204-241 (lines=38) @@ | ||
201 | return big; |
|
202 | }, |
|
203 | ||
204 | indexOfMax: function(start=0, end=-1) { |
|
205 | var vals = this; |
|
206 | ||
207 | // exit quickly if few items .. and checking full array |
|
208 | var len = vals.length; |
|
209 | if (end === -1) { |
|
210 | end = len - 1; |
|
211 | } |
|
212 | if (len === 0 || start > end) { |
|
213 | return -1; |
|
214 | } |
|
215 | ||
216 | // check all values |
|
217 | var big = Number.NEGATIVE_INFINITY; |
|
218 | var slot = -1; |
|
219 | var found = 0; |
|
220 | for (var i = start; i <= end; i++) { |
|
221 | ||
222 | // skip nulls |
|
223 | var val = vals[i]; |
|
224 | if (val != null) { |
|
225 | found++; |
|
226 | var num = val; |
|
227 | if (num > big) { |
|
228 | big = num; |
|
229 | slot = i; |
|
230 | } |
|
231 | } |
|
232 | } |
|
233 | ||
234 | // exit if no non-null values found |
|
235 | if (found === 0) { |
|
236 | return -1; |
|
237 | } |
|
238 | ||
239 | // return calculated max value |
|
240 | return slot; |
|
241 | }, |
|
242 | ||
243 | min: function(start=0, end=-1) { |
|
244 | var vals = this; |
|
@@ 167-202 (lines=36) @@ | ||
164 | return sum; |
|
165 | }, |
|
166 | ||
167 | max: function(start=0, end=-1) { |
|
168 | var vals = this; |
|
169 | ||
170 | // exit quickly if few items .. and checking full array |
|
171 | var len = vals.length; |
|
172 | if (end === -1) { |
|
173 | end = len - 1; |
|
174 | } |
|
175 | if (len === 0 || start > end) { |
|
176 | return 0; |
|
177 | } |
|
178 | ||
179 | // check all values |
|
180 | var big = Number.NEGATIVE_INFINITY; |
|
181 | var found = 0; |
|
182 | for (var i = start; i <= end; i++) { |
|
183 | ||
184 | // skip nulls |
|
185 | var val = vals[i]; |
|
186 | if (val != null) { |
|
187 | found++; |
|
188 | var num = val; |
|
189 | if (num > big) { |
|
190 | big = num; |
|
191 | } |
|
192 | } |
|
193 | } |
|
194 | ||
195 | // exit if no non-null values found |
|
196 | if (found === 0) { |
|
197 | return 0; |
|
198 | } |
|
199 | ||
200 | // return calculated max value |
|
201 | return big; |
|
202 | }, |
|
203 | ||
204 | indexOfMax: function(start=0, end=-1) { |
|
205 | var vals = this; |