lodash#findLast JavaScript Examples

The following examples show how to use lodash#findLast. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Mappers.js    From sampo-ui with MIT License 6 votes vote down vote up
mergeValueToList = (valueList, value) => {
  let old
  if (isObject(value) && value.id) {
    // Check if this object has been constructed earlier
    old = findLast(valueList, function (e) {
      return e.id === value.id
    })
    if (old) {
      // Merge this object to the object constructed earlier
      mergeObjects(old, value)
    }
  } else {
    // Check if this value is present in the list
    old = findLast(valueList, function (e) {
      return isEqual(e, value)
    })
  }
  if (!old) {
    // This is a distinct value
    valueList.push(value)
  }
  return valueList
}