Simple javascript complexity threshold task