skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. Lodash Import Issue

    You are getting the error Cannot find name '_'.ts(2304) because TypeScript doesn’t recognize the underscore _, which is commonly used to represent Lodash, a utility library for JavaScript.

    Follow those steps:

    1. Install Lodash
    npm install lodash
    
    1. Import Lodash
    import _ from 'lodash';
    
    1. The Function
    refSection = filter(weightForHeightRef, (refObject) => {
      return parseFloat(refObject['Length']).toFixed(1) === height;
    });
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search