Boolean expressions - getting mixed up with AND, OR logical operators and how they work
问题 I have to convert a number to comma format. E.g 12345 => 12,345. I have my solution : function convert(n) { n = n.toString(); var result = ''; var count = 0, var idx = n.length - 1; while (r = n[idx]) { count++; result = ((count % 3 == 0 && count != n.length) ? ',' : '') + r + result; idx--; } return result; } But someone else used : result = ((count % 3 != 0 || count == n.length) ? '' : ',') + r + result; They both work but now I am confused about my own solution and just lost why they both