samedi 21 novembre 2020

Write a function that removes any properties on the given object whose values are strings longer than the given number and returns the object

I am writing a function to delete an object with values larger than a given number but everything I seem to be trying is not working.

function removeStringValuesLongerThan(num, obj) {
  for (let prop in obj) {
    if (obj[prop] > num) {
      delete obj[prop];
      }
      return obj;
    }
  }

let competitorDetails = {
  name: 'Montana Slim',
  age: 20,
  location: 'Texas'
}

removeStringValuesLongerThan(6, competitorDetails) 

My code is returning:

{ name: 'Montana Slim', age: 20, location: 'Texas' }

Can anyone give me some hints as to where I am going wrong? I have looked at other similar questions on here but their answers are not helping me.

Aucun commentaire:

Enregistrer un commentaire