Sum of odd numbers

PowerShell

function RowSumOddNumbers([int] $n) {
  return $n * $n * $n;
}

JavaScript

function rowSumOddNumbers(n) {
  let sum = 0, num = 1;
  for (let row = 1; row <= n; row++) {
    for (let i = 0; i < row; i++) {
      if (row == n) sum += num;
      num += 2;
    }
  }

  return sum;
}

Tags

  1. powershell (Private)
  2. javascript (Private)
  3. 7-kyu (Private)
  4. codewars (Private)
  5. answer (Private)