function palindrome(str) { str = str.replace(/[\W_]/g,"").toLowerCase(); for(var i = 0,len = str.length -1 ; i < len/2; i++) { if(str[i] !== str[len-i]) { return false; } } return true;}palindrome("almostomla") ; //falsefunction palindrome(str) { str = str.replace(/[\W_]/g,"").toLowerCase(); for(var i = 0,len = str.length -1 ; i < len/2; i++) { if(str[i] !== str[len-i]) { return false; } return true; } }palindrome("almostomla") ; //true
請問下例中for循環中return和for外return,為什么會導致截然不同的結果?
慕森卡
2018-12-19 18:15:23