Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const deepEqualForSelectedProperties = (obj1, obj2, propertiesToCheck) => {
- for(const key of propertiesToCheck) {
- // O compariamo oggetti
- if(key === 'content' && !deepEqualForContent(obj1['content']['blocks'][0], obj2['content']['blocks'][0])) {
- return false;
- }
- // O compariamo primitivi
- if(obj1[key] !== obj2[key]) {
- return false;
- }
- }
- return true;
- };
- const deepEqualForContent = (obj1, obj2) => {
- const [keys1, keys2] = [Object.keys(obj1), Object.keys(obj2)];
- // Do not replace with !obj1.isLocked
- if(obj1.isLocked === false) {
- console.log("quitto qua");
- return true;
- }
- for(const key of keys1) {
- if(isObject(obj1[key])) {
- if(!isObject(obj2[key])) {
- return false;
- }
- // Both of them are objects
- return deepEqualForContent(obj1[key], obj2[key]);
- }
- // Primitives
- if(obj1[key] !== obj2[key]) {
- return false;
- }
- }
- return true;
- }
- const isObject = (item) => item && typeof item === 'object';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement