Skip to main content
added 642 characters in body
Source Link
Rayn D
  • 227
  • 3
  • 8

update

[
  {
    "providers": [
      {
        "replace": {
          "path": "command1",
          "function": "updateResources",
          "method": "post"
        },
        "save": {
          "path": "test2",
          "function": "updateResources",
          "method": "post"
        }
      }
    ]
  }
]

update

[
  {
    "providers": [
      {
        "replace": {
          "path": "command1",
          "function": "updateResources",
          "method": "post"
        },
        "save": {
          "path": "test2",
          "function": "updateResources",
          "method": "post"
        }
      }
    ]
  }
]
added 12 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155

I use the following code to find if there is duplicate value in property path,This code is working!:

ThisFor example, this is the object configObjconfigObj and as you can see I need to find duplicate in object 'replace' and object 'save' for the value in field 'path'; if they have the same value reject, it rejects with errorerror; otherwise resolveit resolves the promise,is. Is there is more elegant way to write it?

inIn this example, the path is diffrentdifferent (test2 & command1) but it can also be the same.

I use the following code to find if there is duplicate value in property path,This code is working!

This is the object configObj and as you can see I need to find duplicate in object 'replace' and object 'save' for the value in field 'path' if they have the same value reject with error otherwise resolve the promise,is there is more elegant way to write it?

in this example the path is diffrent (test2 & command1) but it can be the same

I use the following code to find if there is duplicate value in property path:

For example, this is the object configObj and as you can see I need to find duplicate in object 'replace' and object 'save' for the value in field 'path'; if they have the same value, it rejects with error; otherwise it resolves the promise. Is there is more elegant way to write it?

In this example, the path is different (test2 & command1) but it can also be the same.

Source Link
Rayn D
  • 227
  • 3
  • 8

Check deep object property and find duplicate value

I use the following code to find if there is duplicate value in property path,This code is working!

return new Promise((resolve, reject) => {
            var data = [];
            Parser.parse()
             //configObj is the value from the screen shot
                .then((configObj) => {
                    configObj.forEach((providers) => {
                        _.each(providers, (provider) => {
                            _.each(provider, (entry) => {
                                for (var prop in entry) {
                                    if (_inArray(entry[prop].path, data)) {
                                        return reject(new Error(`Duplicate path ${entry[prop].path}`));
                                    }
                                    data.push(entry[prop].path);
                                }
                            })
                        })
                    })
                    resolve("validObject");
                }, err => {
                    reject(err);
                });

This is the object configObj and as you can see I need to find duplicate in object 'replace' and object 'save' for the value in field 'path' if they have the same value reject with error otherwise resolve the promise,is there is more elegant way to write it?

enter image description here

in this example the path is diffrent (test2 & command1) but it can be the same