Every | function checkAddressMatch(address1, address2) {
if (!address1 || !address2) {
return false;
}
const fields = [
'address1',
'address2',
'city',
'zip',
'state',
];
return fields.every((field) => address1[field] === address2[field]);
}
checkAddressMatch({
address1: 'address line 1',
address2: 'address line 2',
city: 'Toronto',
zip: undefined,
}, {
address1: 'address line 1',
address2: 'address line 2',
city: 'Toronto',
zip: undefined,
})
| ready |
String | function checkAddressMatch(address1, address2) {
if (!address1 || !address2) {
return false;
}
const fields = [
'address1',
'address2',
'city',
'zip',
'state',
];
const address1Str = fields.map(field => address1[field] || '').join('|').toLowerCase();
const address2Str = fields.map(field => address2[field] || '').join('|').toLowerCase();
return address1Str === address2Str;
}
checkAddressMatch({
address1: 'address line 1',
address2: 'address line 2',
city: 'Toronto',
zip: undefined,
}, {
address1: 'address line 1',
address2: 'address line 2',
city: 'Toronto',
zip: undefined,
})
| ready |
String (Adv) | function checkAddressMatch(address1, address2) {
if (!address1 || !address2) {
return false;
}
const fields = [
'address1',
'address2',
'city',
'zip',
'state',
];
let address1Str = '';
let address2Str = '';
fields.forEach(field => {
address1Str += (address1[field] || '');
address2Str += (address2[field] || '');
});
return address1Str === address2Str;
}
checkAddressMatch({
address1: 'address line 1',
address2: 'address line 2',
city: 'Toronto',
zip: undefined,
}, {
address1: 'address line 1',
address2: 'address line 2',
city: 'Toronto',
zip: undefined,
})
| ready |