How can I understand the split() sorce code quickly!

var str = 'i,am,cool,i,love,wz';
		String.prototype.mySplit = function(sqrt){
			var result = [];
			var a = 0;
			var b = 0;
			console.log(this.length)
			for(var i = 0;i<this.length;i++){
				if(this[i]==sqrt||i==this.length){
					result[b]='';
					//j = a = 0; 
					for(var j = a;j<i;j++){
					  result[b]+=this[j];
					}
					b++;
					a=i+1; 
				}
			}
			return result;
		}
		console.log(str.mySplit(','))

Aww, I just sticking with all things around JavaScript right now. It’s really fun to sticking round with those interesting code.
I can understand this code(no really completly), but it takes a lot time! it’s there any course, or methods that can help me improve my ways to code?

I meant inside for loop, I can’t understand the double for loop well…

Try seeing what it does with this: http://pythontutor.com/javascript.html#mode=edit

1 Like

Thank u very much! It’s a really cool tool!

I recommend always using ===

.

1 Like