Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Type error Scientific API

ANSWERED

Hello! I was trying to use Scientific API for my final thesis but I found this problem using the provided code in the developer module: https://dev.fitbit.com/build/reference/device-api/scientific/

import { scientific } from "scientific";
const arr = new Float32Array(1,2,3,4,5);
const mean = scientific.mean(arr);
const max = scientific.max(arr);
const min = scientific.min(arr);

When I tried to run it in Fitbit Studio it showed the following error: 

Unhandled exception: TypeError: Cannot read property 'mean' of undefined

I checked in package.json which SDK version it's using and it's 3.1 so Scientific API should work. Probably it's an error caused by the type of the array given, but in de module said that it works with Float32Array.

 

Could anyone tell me how to use the Scientific API properly? Thank you.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Sorry, looks like a few issues with that example. I'll ensure the site gets updated.

Here's a working snippet:

import * as scientific from "scientific"
const X = new Float32Array([1,2,3,4,5]);

console.log(`Sum=${scientific.sum(X)}`)
console.log(`Mean=${scientific.mean(X)}`)
console.log(`Max=${scientific.max(X)}`)
console.log(`Min=${scientific.min(X)}`)

You can also checkout the API in action here: https://github.com/Fitbit/sdk-scientific/

 

 

View best answer in original post

Best Answer
0 Votes
1 REPLY 1

Sorry, looks like a few issues with that example. I'll ensure the site gets updated.

Here's a working snippet:

import * as scientific from "scientific"
const X = new Float32Array([1,2,3,4,5]);

console.log(`Sum=${scientific.sum(X)}`)
console.log(`Mean=${scientific.mean(X)}`)
console.log(`Max=${scientific.max(X)}`)
console.log(`Min=${scientific.min(X)}`)

You can also checkout the API in action here: https://github.com/Fitbit/sdk-scientific/

 

 

Best Answer
0 Votes