I believe you that this works, but I can’t easily read or comprehend it without considerable effort, so I’d grade it below a solution I could.
Are you sure? I'm not a javascript programmer and it took less than 2 minutes to comprehend. If you think this takes considerable effort to comprehend then I don't think you actually tried.