Ad
Strings
Parsing
Code
Diff
  • function stripEnds(s, prefix, suffix) {
      return s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '');
    }
    • function stripEnds(s, prefix, suffix) {
    • return s.replace(prefix, '').replace(suffix, '');
    • return s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '');
    • }

Fork from Python BMI calculator made via typescript.

Code
Diff
  • export default class BMI {
      private _height: number;
      private _weight: number;
      
      constructor(weight: number, height: number) {
        this._height = height;
        this._weight = weight;
      }
      
      set height(height: number) {
        if (height <= 0) {
          const invalidValueError = new Error('Invalid value');
          console.error(invalidValueError);
        }
        this._height = height;
      }
      
      set width(weight: number) {
        if (weight <= 0) {
          const invalidValueError = new Error('Invalid value');
          console.error(invalidValueError);
        }
    
        this._weight = weight;
      }
      
      get bmi(): number {
        return Number((this._weight / Math.pow(this._height, 2)).toFixed(2));
      }
      
      calculateBMI(): string {
        return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`;
      }
    }
    • from dataclasses import dataclass
    • export default class BMI {
    • private _height: number;
    • private _weight: number;
    • constructor(weight: number, height: number) {
    • this._height = height;
    • this._weight = weight;
    • }
    • set height(height: number) {
    • if (height <= 0) {
    • const invalidValueError = new Error('Invalid value');
    • console.error(invalidValueError);
    • }
    • this._height = height;
    • }
    • set width(weight: number) {
    • if (weight <= 0) {
    • const invalidValueError = new Error('Invalid value');
    • console.error(invalidValueError);
    • }
    • @dataclass
    • class BMI:
    • height: float
    • weight: float
    • @property
    • def bmi(self) -> float:
    • return self.weight / (self.height ** 2)
    • def calculate_bmi(self) -> str:
    • return f"there {'is no' if self.bmi < 25 else 'is'} excess weight"
    • this._weight = weight;
    • }
    • get bmi(): number {
    • return Number((this._weight / Math.pow(this._height, 2)).toFixed(2));
    • }
    • calculateBMI(): string {
    • return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`;
    • }
    • }