SOURCE

function sortedSquares(nums: number[]): number[] {
	let newNums = []
  while(true){
    if(nums[0]<0){
      for(let j=0;j<nums.length-1;j++){
        let newNumber = Math.abs(-nums[0]);
        if(nums[j]>newNumber){
            nums.splice(j+1,0,newNumber);
            nums.splice(0,1);
            break;
        }
      }
    }else{
        break;
    }
  }
  for (let i of nums){
      newNums.push(i*i)
  }
  return newNums;
};

console.log(sortedSquares([-4,-1,0,3,10]));
console 命令行工具 X clear

                    
>
console