How to make this jQuery snippet more compact?
<pre><code>$selectMenus = $("#experiences").find('select');

$tab.find('input').each(function(i) {
    var $elem = $(this);
    var value = $elem.attr('value');
    if(!value)
     value = '&amp;nbsp;';
    $parent = $elem.parent();
    $elem.remove();
    $parent.html(value);
});

$tab.find('select').each(function(i) {
    $('option', this)[$selectMenus[i].selectedIndex].selected = true;
    var $elem = $(this);
    var value = $elem.attr('value');
    if(!value)
     value = '&amp;nbsp;';
    $parent = $elem.parent();
    $elem.remove();
    $parent.html(value);
});
</code></pre>

<p>Note the two are almost the same.</p>
