JavaScript bubble sort modification (Sorting doesn't happen in some cases.) : I need loop "i" stopped immediately, when sorting will be done.
It doesn't work with all possible values of the array. Sorting doesn't happen in some cases.

[pen link][1]

    var arr = [11, 12, 0, 1, 2, 4, 3, 5, 6, 7, 8, 9, 10, 13];
    var n = arr.length;
    var t;
    var swap = true;

    for (var i = 0; (i < n) && (swap === true); i++) {	
	
	for (var j = 0; j < ( n - (i + 1) ); j++) {
		
	
		if ( arr[j] > arr[j + 1] ) {
			
			t = arr[j + 1];
			arr[j + 1] = arr[j];
			arr[j] = t;
			swap = true;
		
		} else { swap = false; }
    	}
    };


  [1]: https://codepen.io/dandgerson/pen/XgVRKb