Try:
$(".expand-icon").click(function(){
var me = $(this);
var isCollapsed = me.find("a[data-toggle='collapse']").is(".collapsed");
me.find("i.fas").toggleClass("fa-expand-alt", !isCollapsed).toggleClass("fa-compress-alt", isCollapsed);
});
Demo[
^]