Lodash Code Performance

by Roland Doda

JavaScript

const custom_fields = [
  { id: 1, text: "not widen", value: "something" },
  { id: 2, text: "Widen Portal URL", value: "something" },
  { id: 3, text: "not widen", value: "something" }
]
 console.time('function #1')   
   function hasWidenLink() {
      // Check for custom fields
      if (_.isEmpty(custom_fields)) { return false; }

      // Get the field that has Widen Portal (if any)
      let field = _.find(custom_fields, { text: 'Widen Portal URL' });

      // Return if link exists and has a value
      return !_.isEmpty(field) && !_.isEmpty(field.value);
    }


hasWidenLink()
console.timeEnd('function #1')