{"ScriptPreparationCode":"var isUnique = (existingValues) =\u003E {\r\n return function(value) {\r\n value = value.toLowerCase().trim();\r\n\r\n const exists = existingValues.find(ev =\u003E ev.toLowerCase().trim() === value) !== undefined;\r\n\r\n return exists ? false : true;\r\n };\r\n}\r\n\r\nvar keyLookup = (obj, path, defaultValue) =\u003E\r\n path.split(\u0027.\u0027).reduce((a, c) =\u003E (a \u0026\u0026 a[c] ? a[c] : defaultValue || null), obj);\r\n\r\nvar values = {\r\n searchBases: [\r\n { id: \u0022\u0022, node: \u0022c=1\u0022, a: false, b: true },\r\n { id: \u0022\u0022, node: \u0022c=2\u0022, a: false, b: true },\r\n { id: \u0022\u0022, node: \u0022c=3\u0022, a: false, b: true },\r\n { id: \u0022\u0022, node: \u0022c=4\u0022, a: false, b: true },\r\n { id: \u0022\u0022, node: \u0022c=5\u0022, a: false, b: true },\r\n { id: \u0022\u0022, node: \u0022c=6\u0022, a: false, b: true },\r\n { a: true, node: \u0022\u0022 }\r\n ],\r\n};","TestCases":[{"Name":"Regex","Code":"function isUniqueByRef(name) {\r\n return function(value, values) {\r\n\tconst currentValue = value.toLocaleLowerCase().trim();\r\n\r\n // name should be in the form of a.b[x].c\r\n // This regex splits the name so we can iterate over the array.\r\n // In this case, parent is \u0022a.b\u0022 and child and \u0022c\u0022\r\n const [parent, child] = name.split(/\\[\\d\u002B\\]\\./);\r\n\r\n // Extract the index from the name.\r\n // If name is a.b[x].c then match will be \u0022x\u0022\r\n const match = name.match(/[(\\d\u002B)]/g);\r\n\r\n // Convert the value into a number\r\n const currentIndex = Number(match);\r\n\r\n // Get the array from the current form values\r\n // Remove the current index from the list of existing values\r\n const list = keyLookup(values, parent).filter((item, index) =\u003E index !== currentIndex);\r\n\r\n const existingValues = list.map(item =\u003E keyLookup(item, child)).filter(item =\u003E item !== null);\r\n\r\n return isUnique(existingValues)(currentValue);\r\n };\r\n}\r\n\r\nisUniqueByRef(\u0022searchBases[0].node\u0022)(\u0022c=7\u0022, values)","IsDeferred":false},{"Name":"Non-Regex","Code":"function isUniqueByRef(name) {\r\n return function(value, values) {\r\n\tconst currentValue = value.toLocaleLowerCase().trim();\r\n\r\n const start = name.indexOf(\u0027[\u0027);\r\n const end = name.indexOf(\u0027]\u0027);\r\n\r\n const parent = name.substring(0, start);\r\n const child = name.substring(end \u002B 2);\r\n const match = name.substring(start \u002B 1, end);\r\n\r\n // Convert the value into a number\r\n const currentIndex = Number(match);\r\n\r\n // Get the array from the current form values\r\n // Remove the current index from the list of existing values\r\n const list = keyLookup(values, parent).filter((item, index) =\u003E index !== currentIndex);\r\n\r\n const existingValues = list.map(item =\u003E keyLookup(item, child)).filter(item =\u003E item !== null);\r\n\r\n return isUnique(existingValues)(currentValue);\r\n };\r\n}\r\n\r\nisUniqueByRef(\u0022searchBases[0].node\u0022)(\u0022c=7\u0022, values)","IsDeferred":false}]}