A bundle analyzer checks where a known code snippet first appears inside a minified bundle.
Write firstIndex(bundle, snippet) that returns the smallest index where snippet starts in bundle, or -1 if it doesn't appear. Don't use indexOf, includes, or regular expressions: compare windows yourself.
Input: bundle = "var a=1;function f(){return a}", snippet = "function" Output: 8
function starts right after var a=1;.
Input: bundle = "abc", snippet = "d" Output: -1
d never appears.
0 <= bundle.length <= 10^51 <= snippet.length <= 10^3Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #616 Find a Snippet in a Bundle. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.