Say number generator

by rishul matta

JavaScript

function gen(A) {
	A--;

	var stack = [];
	var seed = 1;
	nos = null;
	var newSeed = [];
	
	while (A > 0) {
		var quo = -1;
		while (quo != 0) {
			quo = parseInt(seed / 10);
			rem = seed % 10;
			seed = quo;
			stack.push(rem);
		}
		counter = 0;
		nos = null;
		while(stack.length) {
			first = stack.pop();
			if (first == nos) {
				counter++;
			}
			if (nos == null) {
				nos = first;
				counter = 1;
			}

			if (first != nos) {
				newSeed.push(counter);
				newSeed.push(nos);
				nos = first;
				counter = 1;
			}
			
			if (first == nos && stack.length == 0) {
				newSeed.push(counter);
				newSeed.push(nos);
			}
		}
		
		

		
		seed = parseInt(newSeed.join(""));
		//console.log(parseInt(newSeed.join("")))
		newSeed = [];
		A--;
	}
	return seed;
}