objetos - sort array object javascript
Coincidencia de objetos en Array y Consolidar (4)
Abordaría este problema de manera muy diferente. Para comenzar, la siguiente solución debería ponerlo en el camino correcto. Basado en el conjunto de datos provisto, también debe cumplir todos (o la mayoría) de sus requisitos.
const carsUniq = new Map()
cars.forEach($car => {
const cKeys = $car.data()
const carAttrsId = [
cKeys.dropoffLocationId,
cKeys.locationId,
cKeys.type,
cKeys.vehicleExample
].join('''')
const sCar = carsUniq.get(carAttrsId)
if (!sCar) {
carsUniq.set( carAttrsId, cKeys )
} else {
for(const c in sCar) {
if ( !sCar[c] && cKeys[c] ) sCar[c] = cKeys[c]
}
}
})
-
¿Como funciona?
- Crear un mapa para el seguimiento de coches.
- Determine si un automóvil es un duplicado haciendo referencia a los accesorios específicos del automóvil a
carAttrsId
. [O (1) búsqueda] - Si se encuentra un automóvil en el Mapa, debe ser un duplicado, por lo que combinamos los conjuntos de datos en un objeto normalizado.
- El resultado final es
carsUniq.values()
es una matriz como objeto de autos únicos.
-
Basado en su conjunto de datos carsUniq
contendrá 3 autos únicos :
"SX-34.0910834--118.352194SX-34.0910834--118.352194ICARChevrolet Cruze" => {…}
"ZR-34.1958--118.3489ZR-34.1958--118.3489IDARToyota Corolla" => {…}
"FX-34.0629025--117.6140867FX-34.0629025--117.6140867SCAR" => {…}
-
Actualización: código anterior mejorado y función agregada para convertir elementos a elementos li según lo solicitado.
const carsUniq = new Map()
cars.forEach($car => {
const cKeys = $car.data()
const { dropoffLocationId, locationId, type, vehicleExample } = cKeys
const carAttrsId = dropoffLocationId + locationId + type + vehicleExample;
const sCar = carsUniq.get(carAttrsId)
if (!sCar) {
carsUniq.set( carAttrsId, cKeys )
} else {
for(const c in sCar) {
if ( !sCar[c] && cKeys[c] ) sCar[c] = cKeys[c]
}
}
})
const dasherizedCarKeys = new Map()
const dasherizedData = str => {
const k = dasherizedCarKeys.get(str)
if (!k) {
dasherizedCarKeys.set(str,
''data-'' + str.replace(/([a-zA-Z])(?=[A-Z])/g, ''$1-'').toLowerCase())
}
return k
}
carsUniq.forEach(car => {
const tCar = {}
const carKeys = Object.keys(car).map(dasherizedData)
for (const c in car) {
tCar[dasherizedCarKeys.get(c)] = car[c]
}
$(''<li>'').attr(tCar).appendTo("#output")
})
Salida:
<li data-vehicle-example="Chevrolet Cruze" data-original-price="180.15" data-price="180.15" data-type="ICAR" data-dropoff-location-id="SX-34.0910834--118.352194" data-location-id="SX-34.0910834--118.352194"></li>
<li data-vehicle-example="Toyota Corolla" data-price="301.43" data-type="IDAR" data-dropoff-location-id="ZR-34.1958--118.3489" data-location-id="ZR-34.1958--118.3489"></li>
<li data-price="198.81" data-type="SCAR" data-partner-code="FX" data-dropoff-location-id="FX-34.0629025--117.6140867" data-location-id="FX-34.0629025--117.6140867"></li>
ACTUALIZAR:
Tengo una serie de objetos llamados cars
que contienen etiquetas li con datos de atributos sobre automóviles (como el precio, el tipo de automóvil, etc.). Mi objetivo es consolidar estos autos en una sola lista si son una coincidencia basada en ciertos criterios.
Requerimientos
- Rendimiento rápido
- Mantener la misma estructura de matriz de coches
- Objetivo principal: hacer coincidir los listados de prepago y minorista: combine el HTML del listado de minoristas (como el botón y la información de precios) en el listado de prepago. Ver:
- Si hay una coincidencia (basada en los criterios de la declaración IF), elimine la lista coincidente sin la clase "lista prepaga" Y actualice la lista prepaga coincidente con cierta información de la lista minorista.
Matriz de coches:
<li xmlns="http://www.w3.org/1999/xhtml" id="listing-CCAR-RM-AD-SFBT003-AD-SFBT003" data-location-id="AD-28.7455--81.2411" data-dropoff-location-id="AD-28.7455--81.2411" data-partner-name="Advantage" data-partner-code="AD" data-type="CCAR" data-vehicle-class-description="Compact Car" data-seats="5" data-bags="2" data-counter-type="ON_AIRPORT" data-prepaid="Y" data-fare-type="PREPAID" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="34.81" data-original-price="35.70" data-base-price="24.25" data-vehicle-example="Nissan Versa" data-highlighted="N" data-deal="Y" class="listing listing-prepaid" data-original-position="18"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>5</span></li><li class="bags"><span>2</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Compact</span><b></b></a></h3><span class="car-example">Nissan Versa or similar<sup>†</sup></span><span class="counter-type airport">Car on Airport</span></div><div class="features"><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>SFB: Orlando Sanford Intl Airport</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><span class="car-badge prepaid">Pay Now & Save 2%</span><div class="container retail prepaid"><div class="rate"><span class="strikethrough"><span class="price-original">$25</span></span><span class="cur-symbol">$</span><span class="price">24</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Pay Now</a></p><span class="total">Total: $<span class="price">34</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>
<li xmlns="http://www.w3.org/1999/xhtml" id="listing-ECAR-RP-HZ-ORLN003-HZ-ORLN003" data-location-id="HZ-28.5042--81.4284" data-dropoff-location-id="HZ-28.5042--81.4284" data-partner-name="Hertz" data-partner-code="HZ" data-type="ECAR" data-vehicle-class-description="Economy Car" data-seats="4" data-bags="1" data-counter-type="" data-prepaid="Y" data-fare-type="PREPAID" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="36.34" data-original-price="39.95" data-base-price="29.83" data-vehicle-example="Chevrolet Spark" data-highlighted="N" data-deal="Y" class="listing listing-prepaid" data-original-position="30"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>4</span></li><li class="bags"><span>1</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Economy</span><b></b></a></h3><span class="car-example">Chevrolet Spark or similar<sup>†</sup></span></div><div class="features"><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>3575 Vineland Road, Orlando, FL</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><span class="car-badge prepaid">Pay Now & Save 9%</span><div class="container retail prepaid"><div class="rate"><span class="strikethrough"><span class="price-original">$33</span></span><span class="cur-symbol">$</span><span class="price">29</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Pay Now</a></p><span class="total">Total: $<span class="price">36</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>
<li xmlns="http://www.w3.org/1999/xhtml" id="listing-CCAR-R-AD-SFBT003-AD-SFBT003" data-location-id="AD-28.7455--81.2411" data-dropoff-location-id="AD-28.7455--81.2411" data-partner-name="Advantage" data-partner-code="AD" data-type="CCAR" data-vehicle-class-description="Compact Car" data-seats="5" data-bags="2" data-counter-type="ON_AIRPORT" data-prepaid="N" data-fare-type="RETAIL" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="35.70" data-base-price="25.00" data-vehicle-example="Nissan Versa" data-highlighted="N" data-deal="N" class="listing" data-original-position="22"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>5</span></li><li class="bags"><span>2</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Compact</span><b></b></a></h3><span class="car-example">Nissan Versa or similar<sup>†</sup></span><span class="counter-type airport">Car on Airport</span></div><div class="features"><span>Free Cancellation</span><span>Pay at Pick-up</span><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>SFB: Orlando Sanford Intl Airport</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><div class="container retail"><div class="rate"><span class="cur-symbol">$</span><span class="price">25</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Select Car</a></p><span class="total">Total: $<span class="price">35</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>
<li xmlns="http://www.w3.org/1999/xhtml" id="listing-ECAR-R-EX-MCOO001-EX-MCOO001" data-location-id="EX-28.4514095--81.3577729" data-dropoff-location-id="EX-28.4514095--81.3577729" data-partner-name="Executive" data-partner-code="EX" data-type="ECAR" data-vehicle-class-description="Economy Car" data-seats="2" data-bags="1" data-counter-type="OFF_AIR_SHTL" data-prepaid="N" data-fare-type="RETAIL" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="28.78" data-base-price="14.58" data-vehicle-example="SmartCar" data-highlighted="N" data-deal="N" class="listing" data-original-position="2"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>2</span></li><li class="bags"><span>1</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Economy</span><b></b></a></h3><span class="car-example">SmartCar or similar<sup>†</sup></span><span class="counter-type shuttle">Shuttle to Car</span></div><div class="features"><span>Pay at Pick-up</span><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>MCO: Orlando Intl Airport</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><div class="container retail"><div class="rate"><span class="cur-symbol">$</span><span class="price">14</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Select Car</a></p><span class="total">Total: $<span class="price">28</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>
Rendimiento esperado:
En la matriz de ejemplo anterior, los listados primero y tercero deben coincidir (ya que tienen el mismo tipo de auto, identificaciones de ubicación, ejemplo de vehículo, etc.). La primera lista debe eliminarse de la matriz, ya que no tiene clase de lista prepaga Y el HTML dentro de .column-price se debe agregar a su conciliación prepaga (en este ejemplo, la tercera lista de la matriz).
Producto final:
Código:
cars = cars.reduce((acc, car) => {
let retail_match = false;
cars.forEach(car2 => {
if (((car[0].hasAttribute("data-original-price") && car[0].getAttribute("data-original-price") === car2[0].getAttribute("data-price")) || (car2[0].hasAttribute("data-original-price") && car2[0].getAttribute("data-original-price") === car[0].getAttribute("data-price"))) && (car[0].getAttribute("data-base-price") != car2[0].getAttribute("data-base-price")) && (car[0].getAttribute("data-price") != car2[0].getAttribute("data-price")) && (car[0].getAttribute("data-type") == car2[0].getAttribute("data-type")) && (car[0].getAttribute("data-vehicle-example") == car2[0].getAttribute("data-vehicle-example")) && (car[0].getAttribute("data-location-id") == car2[0].getAttribute("data-location-id")) && (car[0].getAttribute("data-dropoff-location-id") == car2[0].getAttribute("data-dropoff-location-id")))
{
if (!car.hasClass("listing-prepaid"))
retail_match = true;
else
{
car.find(".column-price")
.addClass("prepaid-match")
.append(car2.find(".column-price div.retail"))
.find("div.retail:not(.prepaid) p.button a").text("Pay Later");
}
}
});
if (!retail_match)
acc.push(car);
return acc;
}, []);
Como se mencionó en los comentarios, el uso de reduce mantiene la complejidad en O (n) . Básicamente, esto significa que una lista que duplica el tamaño tomará el doble del tiempo, ya que el algoritmo solo itera la lista de autos una vez.
Si necesita comparar cada elemento de la matriz de autos entre sí en la matriz de automóviles, la complejidad de los enfoques en forma de bucle será ne O (n ^ 2) , ya que para cada elemento adicional (más o menos) habrá exponencialmente más Bucles / tiempo utilizado.
No estoy 100% seguro de la estructura de datos de sus objetos javascript, pero el siguiente enfoque debería funcionar:
const allCars = []; // An array of cars, each item is a HTMLElement
let matchedCars = allCars.reduce((acc, car, cars) => {
cars.forEach(car2 => {
// For every car iterate over the cars array again to compare car to every item in the cars array (leave out this loop if you don''t need the extensive comparison)
if (car.hasAttribute("data-original-price")
&& car2.getAttribute("data-original-price") === car.getAttribute("data-price")
/* Add additional matching criteria here, you may access cars to get info about other cars than the current car */) {
// Add the desired class for a match
car.classList.add(''listing-prepaid'');
// Add the matched car to the accumulator, so it ends up in the matchedCars array
acc.push(car);
}
});
}, [];
Un enfoque alternativo sería construir una estructura de datos que permita el acceso a elementos basados en sus atributos en un tiempo constante ( O (1) ). Un ejemplo sería un (Hash)Map . En este caso, para cada elemento en el que el algoritmo está en bucle, no es necesario que se repita en toda la lista nuevamente para identificar coincidencias pero para consultar las coincidencias de la estructura del Mapa.
Bonificación: Dado que el automóvil es un HTMLElement, puede usar la propiedad del conjunto de datos para acceder a los valores de datos * más fácilmente con:
car.dataset.originalPrice === car.dataset.price
Lea más sobre esto en https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
Fuentes generales: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement , https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
Hubo un error en el código, como, cuando accede al elemento HTML desde la matriz en js, devuelve cadenas en lugar de objetos HTML, por lo que no puede acceder a él significa que no puede aplicar JS / Jquery hasAttribute y otras funciones en él. , Lo he arreglado y puedes encontrar el ejemplo de trabajo en el violín, el enlace se muestra a continuación:
var cars = [''<li xmlns="http://www.w3.org/1999/xhtml" id="listing-CCAR-RM-AD-SFBT003-AD-SFBT003" data-location-id="AD-28.7455--81.2411" data-dropoff-location-id="AD-28.7455--81.2411" data-partner-name="Advantage" data-partner-code="AD" data-type="CCAR" data-vehicle-class-description="Compact Car" data-seats="5" data-bags="2" data-counter-type="ON_AIRPORT" data-prepaid="Y" data-fare-type="PREPAID" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="34.81" data-original-price="35.70" data-base-price="24.25" data-vehicle-example="Nissan Versa" data-highlighted="N" data-deal="Y" class="listing listing-prepaid" data-original-position="18"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>5</span></li><li class="bags"><span>2</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Compact</span><b></b></a></h3><span class="car-example">Nissan Versa or similar<sup>†</sup></span><span class="counter-type airport">Car on Airport</span></div><div class="features"><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>SFB: Orlando Sanford Intl Airport</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><span class="car-badge prepaid">Pay Now & Save 2%</span><div class="container retail prepaid"><div class="rate"><span class="strikethrough"><span class="price-original">$25</span></span><span class="cur-symbol">$</span><span class="price">24</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Pay Now</a></p><span class="total">Total: $<span class="price">34</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>'', ''<li xmlns="http://www.w3.org/1999/xhtml" id="listing-ECAR-RP-HZ-ORLN003-HZ-ORLN003" data-location-id="HZ-28.5042--81.4284" data-dropoff-location-id="HZ-28.5042--81.4284" data-partner-name="Hertz" data-partner-code="HZ" data-type="ECAR" data-vehicle-class-description="Economy Car" data-seats="4" data-bags="1" data-counter-type="" data-prepaid="Y" data-fare-type="PREPAID" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="36.34" data-original-price="39.95" data-base-price="29.83" data-vehicle-example="Chevrolet Spark" data-highlighted="N" data-deal="Y" class="listing listing-prepaid" data-original-position="30"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>4</span></li><li class="bags"><span>1</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Economy</span><b></b></a></h3><span class="car-example">Chevrolet Spark or similar<sup>†</sup></span></div><div class="features"><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>3575 Vineland Road, Orlando, FL</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><span class="car-badge prepaid">Pay Now & Save 9%</span><div class="container retail prepaid"><div class="rate"><span class="strikethrough"><span class="price-original">$33</span></span><span class="cur-symbol">$</span><span class="price">29</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Pay Now</a></p><span class="total">Total: $<span class="price">36</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>'', ''<li xmlns="http://www.w3.org/1999/xhtml" id="listing-CCAR-R-AD-SFBT003-AD-SFBT003" data-location-id="AD-28.7455--81.2411" data-dropoff-location-id="AD-28.7455--81.2411" data-partner-name="Advantage" data-partner-code="AD" data-type="CCAR" data-vehicle-class-description="Compact Car" data-seats="5" data-bags="2" data-counter-type="ON_AIRPORT" data-prepaid="N" data-fare-type="RETAIL" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="35.70" data-base-price="25.00" data-vehicle-example="Nissan Versa" data-highlighted="N" data-deal="N" class="listing" data-original-position="22"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>5</span></li><li class="bags"><span>2</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Compact</span><b></b></a></h3><span class="car-example">Nissan Versa or similar<sup>†</sup></span><span class="counter-type airport">Car on Airport</span></div><div class="features"><span>Free Cancellation</span><span>Pay at Pick-up</span><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>SFB: Orlando Sanford Intl Airport</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><div class="container retail"><div class="rate"><span class="cur-symbol">$</span><span class="price">25</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Select Car</a></p><span class="total">Total: $<span class="price">35</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>'', ''<li xmlns="http://www.w3.org/1999/xhtml" id="listing-ECAR-R-EX-MCOO001-EX-MCOO001" data-location-id="EX-28.4514095--81.3577729" data-dropoff-location-id="EX-28.4514095--81.3577729" data-partner-name="Executive" data-partner-code="EX" data-type="ECAR" data-vehicle-class-description="Economy Car" data-seats="2" data-bags="1" data-counter-type="OFF_AIR_SHTL" data-prepaid="N" data-fare-type="RETAIL" data-transmission="Automatic" data-unlimited-miles="Y" data-preferred="N" data-price="28.78" data-base-price="14.58" data-vehicle-example="SmartCar" data-highlighted="N" data-deal="N" class="listing" data-original-position="2"><div class="row"><div class="column column-images"><div class="img-wrapper"><ul class="icons"><li class="people"><span>2</span></li><li class="bags"><span>1</span></li></ul></div></div><div class="column car-details"><div class="car-title"><h3><a><span class="car-class">Economy</span><b></b></a></h3><span class="car-example">SmartCar or similar<sup>†</sup></span><span class="counter-type shuttle">Shuttle to Car</span></div><div class="features"><span>Pay at Pick-up</span><span>Unlimited Miles</span></div><div class="car-location-container"><div class="car-location"><h6>Pick-up</h6>MCO: Orlando Intl Airport</div><div class="car-location"><h6>Drop-off</h6>Same as pick-up</div></div></div><div class="column column-price"><div class="container retail"><div class="rate"><span class="cur-symbol">$</span><span class="price">14</span><span class="rate-plan">/day</span></div><p class="button"><a class="button">Select Car</a></p><span class="total">Total: $<span class="price">28</span></span></div></div></div><b style="clear:both;display:block;height:1px;width:1px"></b></li>''];
cars = cars.reduce((acc, car) => {
let retail_match = false;
cars.forEach(car2 => {
if ((($(car)[0].hasAttribute("data-original-price") && $(car)[0].getAttribute("data-original-price") === $(car2)[0].getAttribute("data-price")) || ($(car2)[0].hasAttribute("data-original-price") && $(car2)[0].getAttribute("data-original-price") === $(car)[0].getAttribute("data-price"))) && ($(car)[0].getAttribute("data-base-price") != $(car2)[0].getAttribute("data-base-price")) && ($(car)[0].getAttribute("data-price") != $(car2)[0].getAttribute("data-price")) && ($(car)[0].getAttribute("data-type") == $(car2)[0].getAttribute("data-type")) && ($(car)[0].getAttribute("data-vehicle-example") == $(car2)[0].getAttribute("data-vehicle-example")) && ($(car)[0].getAttribute("data-location-id") == $(car2)[0].getAttribute("data-location-id")) && ($(car)[0].getAttribute("data-dropoff-location-id") == $(car2)[0].getAttribute("data-dropoff-location-id"))) {
if (!$(car).hasClass("listing-prepaid"))
retail_match = true;
else {
$(car).find(".column-price")
.addClass("prepaid-match")
.append($(car2).find(".column-price div.retail"))
.find("div.retail:not(.prepaid) p.button a").text("Pay Later");
}
console.log(retail_match);
}
});
if (!retail_match)
acc.push(car);
return acc;
}, []);
console.log(cars);
[jsfiddle][1]
I hope this will solve your issue, Let me know if you''ve any question. Thanks
[1]: https://jsfiddle.net/harshsri/93qbghgk/
No estoy seguro si entiendo la pregunta, pero este código es similar a su enfoque, excepto que los cars
solo, según los datos de ejemplo , tienen un elemento, que es el tercer li
en los datos. (Las diversas condiciones if
se formatean para una fácil visualización.)
cars = cars.reduce( ( ca, car2, ci, a ) => {
let b = $.isArray( ca ) ? ca : [];
a.forEach( car => {
if (
(
( car.attr( ''data-original-price'' ) && car.attr( ''data-original-price'' ) === car2.attr( ''data-price'' ) ) ||
( car2.attr( ''data-original-price'' ) && car2.attr( ''data-original-price'' ) === car.attr( ''data-price'' ) )
) &&
( car.attr( ''data-base-price'' ) !== car2.attr( ''data-base-price'' ) ) &&
( car.attr( ''data-price'' ) !== car2.attr( ''data-price'' ) ) &&
( car.attr( ''data-type'' ) === car2.attr( ''data-type'' ) ) &&
( car.attr( ''data-vehicle-example'' ) === car2.attr( ''data-vehicle-example'' ) ) &&
( car.attr( ''data-location-id'' ) === car2.attr( ''data-location-id'' ) ) &&
( car.attr( ''data-dropoff-location-id'' ) === car2.attr( ''data-dropoff-location-id'' ) )
) {
if ( car.hasClass( ''listing-prepaid'' ) ) {
car.find( ''.column-price'' )
.addClass( ''prepaid-match'' )
.append( car2.find( ''.column-price div.retail'' ) )
.find( ''div.retail:not(.prepaid) p.button a'' )
.text( ''Pay Later'' );
b.push( car );
}
}
} );
return b;
} );