So I am trying to create a react function that Calculates Weight For Height Zscore
Here is an example of my code
calcWeightForHeightZscore(weightForHeightRef, height, weight) {
let refSection;
let formattedWHValue;
if (height && weight) {
height = parseFloat(height).toFixed(1);
}
const standardHeightMin = 45;
const standardMaxHeight = 110;
if (height < standardHeightMin || height > standardMaxHeight) {
formattedWHValue = -4;
} else {
refSection = _.filter(weightForHeightRef, (refObject) => {
return parseFloat(refObject['Length']).toFixed(1) === height;
});
}...............
}
However I am faced with this error
Cannot find name '_'.ts(2304)
Any help how I can tackle this
I expect it to return zscore when used, but how would I approach tackling this error better
2
Answers
You’re trying to use
_
(which I assume is lodash), but it cannot be found.Make sure you’re installed the package and imported it
Lodash Import Issue
You are getting the error Cannot find name
'_'.ts(2304)
becauseTypeScript
doesn’t recognize the underscore_
, which is commonly used to representLodash
, a utility library forJavaScript
.Follow those steps:
Lodash
After following these instructions, the error should no longer appear, allowing you to incorporate
Lodash
into your function.Ensure that you input numeric values for both height and weight, and verify that
weightForHeightRef()
is an array with the correct formatting for its objects.Once these concerns have been addressed, you can proceed with developing your function to compute the Z-Score.