Skip to content

Commit 87c23d5

Browse files
authored
Merge pull request #2344 from adafruit/TheKitty-patch-2
Fix index out of range error
2 parents f4f4c88 + f0398d5 commit 87c23d5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Trinket_Ultrasonic_Rangefinder/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
Code to accompany this tutorial:
44
https://learn.adafruit.com/trinket-ultrasonic-rangefinder
5+
6+
Currently limited to M0 versions due to an issue in the Arduino IDE

Trinket_Ultrasonic_Rangefinder/code.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def find_mode(x):
8181
"""
8282
n = len(x)
8383

84+
if n == 0: # If somehow there is a null array
85+
return 0
86+
87+
if n == 1: # In trivial case of a one element array
88+
return x[0] # just return the element as the mode.
89+
8490
max_count = 0
8591
mode = 0
8692
bimodal = 0

0 commit comments

Comments
 (0)