text: function isPrime(n) {
  	if (n === 1) {
  		return false;
  	}
  	for (let i = 2; i <= parseInt(Math.sqrt(n), 10); i++) {
  		if (n % i === 0) {
  			return false;
  		}
  	}
  	return true;
  }
  
  function ulamSpiral(dimensions) {
  	if (dimensions % 2 === 0) {
  		throw new Error();
  	}
  
  	const primeArray = [];
  	for (let i = 1; i <= dimensions * dimensions; i++) {
  		if (isPrime(i)) {
  			primeArray.push(true);
  		} else {
  			primeArray.push(false);
  		}
  	}
  
  	const spiralArray = new Array(dimensions).fill("").map(() => new Array(dimensions).fill(""));
  
  	let direction = "left";
  	let x = dimensions - 1;
  	let y = dimensions - 1;
  
  	for (let i = (dimensions ** 2) - 1; i >= 0; i--) {
  		spiralArray[x][y] = primeArray[i] ? "*" : "-";
  
  		switch (direction) {
  			case "up":
  				if (x === 0 || spiralArray[x - 1][y] !== "") {
  					direction = "right";
  					y += 1;
  					break;
  				}
  				x -= 1;
  				break;
  			case "down":
  				if (x === dimensions - 1 || spiralArray[x + 1][y] !== "") {
  					direction = "left";
  					y -= 1;
  					break;
  				}
  				x += 1;
  				break;
  			case "left":
  				if (y === 0 || spiralArray[x][y - 1] !== "") {
  					direction = "up";
  					x -= 1;
  					break;
  				}
  				y -= 1;
  				break;
  			case "right":
  				if (y === dimensions - 1 || spiralArray[x][y + 1] !== "") {
  					direction = "down";
  					x += 1;
  					break;
  				}
  				y += 1;
  				break;
  			default:
  				throw new Error("not a valid direction");
  		}
  	}
  
  	for (const row of spiralArray) {
  		let rowStr = "";
  		for (const col of row) {
  			rowStr += col;
  		}
  		console.log(rowStr);
  	}
  }
  
  ulamSpiral(19);
  