Javascript ECMAScript 5: arrays merging and deduction -
i have got 3 arrays:
presententities = ['1', '2', '3']; addedentities = ['3', '4']; removedentities = ['2'];
i need:
mergepresententities
addedentities
, take business relationship possible duplicates (means need set) deduct removedentities
result expected result:
['1', '3', '4']
question: true way in javascript?
here ecmascript 5 compatible way:
class="snippet-code-js lang-js prettyprint-override">var presententities = ['1', '2', '3']; var addedentities = ['3', '4']; var removedentities = ['2']; var uniqueentities = addedentities.filter(function(value) { if (presententities.indexof(value) === -1) homecoming value; }); mergedentities = presententities.concat(uniqueentities); var finalentities = mergedentities.filter(function(value) { if (removedentities.indexof(value) === -1) homecoming value; }); document.body.innerhtml = json.stringify(finalentities);
javascript
No comments:
Post a Comment