Replacing nested loop in JavaScript

join shbcf.ru