New answers tagged

4

Neither of your solutions handles the type of the replacement correctly. For instance "bar.baz.foo:111222" replaces foo:333444 with foo:"111222" where I would expect it to result in foo:111222. Further they can handle if the replacement is an array, but not if it is an object due to the use of split(':'). You should use str.indexOf(':') ...


0

I think I found solution much cleaner and simpler to understand: https://codereview.stackexchange.com/a/240907/227075 That solution adjusted to my task const testStr = 'bar.baz.foo:111222'; const testObj = { bar: { baz: { foo: '333444', }, }, }; console.log('[before] testObj.bar.baz =', testObj.bar.baz); // run replaceInObj(testObj, ...


2

For an interview, this is bad code. It is \$O(n \log n)\$. But it can be done in \$O(n)\$ time. Your code does not show your skills in that direction. Also, many interviewers (justifiably) will be unhappy for using streams. Streams may look cute but at scale like Gmail, they cause performance problems.


4

Avoid using in header files It looks like the code you have written is in a header file, which is to be included in an actual application that needs to intersect polygons. If you include this file, it also means you pull in all the using declarations, which could result in unexpected behavior. It might be safe to move the using declarations into class ...


Top 50 recent answers are included