Timeline for Check if an array contains another array with the same consecutive ordering of elements
Current License: CC BY-SA 4.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 16, 2022 at 9:59 | comment | added | hellopeach |
your solution fails when it's testing something like test([1, 2, 3, [10, 1000]], [3, [10, 1000]]) where the JSON.stringify hack works fine.
|
|
| Oct 15, 2022 at 15:38 | history | edited | danh | CC BY-SA 4.0 |
added 828 characters in body
|
| Oct 15, 2022 at 15:20 | comment | added | danh | I see it now. I read "contains with the same ordering", literally, and I missed that the OP expects false. I'll make an edit to offer an alternative. (an alternative in case the OP mis-stated their expectation). | |
| Oct 15, 2022 at 15:10 | comment | added | Sebastian Simon |
The same as mentioned in the question: false.
|
|
| Oct 15, 2022 at 15:06 | comment | added | danh | @SebastianSimon, What result do you expect for test(target, [2, 4]) ? | |
| Oct 15, 2022 at 14:59 | comment | added | Sebastian Simon |
I just noticed, this fails the test(target, [2, 4]) test. index is just the first occurrence within the big array of the next element within the small array, which doesn’t guarantee that all elements must be consecutive.
|
|
| Oct 15, 2022 at 14:53 | comment | added | danh | Smart catch, @SebastianSimon. The entry condition was too lax. Only [] is a subset of []. Edited | |
| Oct 15, 2022 at 14:52 | history | edited | danh | CC BY-SA 4.0 |
added 85 characters in body
|
| Oct 15, 2022 at 14:35 | history | answered | danh | CC BY-SA 4.0 |