Asked
— Edited

Hello @Athena,
I'm currently working on a project where I need to sort values and utilize the lowest value within my script using Synthiam ARC. I believe that utilizing an array in JavaScript is the appropriate approach. Although I have researched JavaScript commands and sorting techniques, I would appreciate some assistance to jumpstart my implementation process.
Objectives:
- Capture a single servo's position and take five sample readings from an infrared (IR) sensor. I need to sort these readings to find the lowest value and associate this lowest IR reading with the current servo position.
- Repeat the first step for nine consecutive servo positions.
- Identify which servo position corresponds to the lowest IR value among all the sampled positions.
Could you provide an example of how to structure an array in JavaScript within ARC to achieve these objectives?
Thank you for your support,
Jack
Related Hardware Roli Rover
Hi Jack,
I'm glad to hear the code is working perfectly for you!
For a deeper dive into arrays and their structure in JavaScript, here are some resources and tips that might help:
MDN Web Docs - Arrays:
The MDN site is an excellent resource for learning JavaScript arrays, including methods, properties, and best practices. Check out the MDN Arrays Reference for detailed explanations and examples.
Synthiam Programming Guide:
Our Synthiam Programming Guide covers some fundamental programming concepts including arrays. You can review it at Synthiam Programming Guide. This guide is tailored to working with ARC, so it can be especially relevant for your projects.
Online Tutorials & Videos:
There are plenty of JavaScript tutorials on platforms like YouTube and freeCodeCamp that cover arrays in depth. Simply searching for "JavaScript arrays tutorial" can yield several step-by-step videos.
Experiment and Debug:
print()
function in your ARC JavaScript scripts to log array contents or individual elements.If you have any more questions about arrays or need further clarification on aspects of the coding architecture (like phases 4 and 5), feel free to ask. I'm happy to help further as you explore these new concepts.
Happy coding,
Athena
I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
Hi @ Athena, Please review the following code from above:
My question is about " var lowValue = Number.MAX_VALUE". I understand var lowValue will be the ultimate low value of the three samples taken. What does "Number.MAX_VALUE" mean? Does it revert to a high number after 1 degree change when the 'for' loop cycles again with 3 samples?
Thanks Jack
Hi Jack,
Great question! Let me explain what that line does:
What is Number.MAX_VALUE?
How It Works in Your Code
In your code snippet:
Initialization:
lowValue
toNumber.MAX_VALUE
.Number.MAX_VALUE
and thus will updatelowValue
.Within the Loop:
lowValue
.lowValue
is updated to that reading.For Each Degree:
lowValue
is reinitialized toNumber.MAX_VALUE
again for each new degree scan.Summary
lowValue
is reset toNumber.MAX_VALUE
so that previous readings do not affect the current measurement.I hope this clears things up! If you have any more questions or need further explanation on arrays or any other topic, feel free to ask.
Happy coding,
Athena
I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
Hi @ Athena, What other Methods can be called on the "NUMBER" Class? Thanks Jack
Below is an overview of some useful methods and properties provided by JavaScript's Number, which can be very handy when working with numeric data:
Static Methods and Properties on the Number Class
Number.MAX_VALUE
The largest positive representable number.
Number.MIN_VALUE
The smallest positive representable number-that is, the positive number closest to zero.
Number.POSITIVE_INFINITY
A value representing infinity (returned on overflow).
Number.NEGATIVE_INFINITY
A value representing negative infinity.
Number.NaN
Represents "Not-A-Number."
Number.isFinite(value)
Determines whether the passed value is a finite number.
Example:
Number.isInteger(value)
Checks whether the passed value is an integer.
Example:
Number.isNaN(value)
Determines whether the passed value is NaN (Not-a-Number).
Example:
Number.parseFloat(string) (alias: parseFloat())
Parses a string argument and returns a floating point number.
Example:
Number.parseInt(string, [radix]) (alias: parseInt())
Parses a string and returns an integer of the specified radix (base).
Example:
Instance Methods on Number (when using a Number instance)
When a number is wrapped as an object, several methods are available on its prototype:
toFixed(digits)
Returns a string representing the number fixed to a specified number of decimal places.
Example:
toExponential(fractionDigits)
Returns a string representing the number in exponential notation.
Example:
toPrecision(precision)
Returns a string representing the number to the specified precision.
Example:
toLocaleString()
Returns a string with a language-sensitive representation of the number.
Example:
Learning More
For additional details and working examples, the MDN Web Docs are an excellent resource. You can explore the full reference here:
MDN Number documentation
I hope this helps! If you have more questions or need further assistance with Synthiam ARC scripting or anything else, feel free to ask.
Happy coding,
Athena
I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.