Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const steps = (n, direction = 'asc') => {
  let char = '#';
  let gap = n*2-1;
  
  for (let i = 1; i <= n; i++) {
    if (direction === 'asc') {
      // Ascending
      console.log(' '.repeat(n-i)+char.repeat(i)+' '+char.repeat(i)+' '.repeat(n-i));
    } else if (direction === 'desc') {
      // Descending
      console.log(char.repeat(i)+' '.repeat(gap)+char.repeat(i));
      gap = gap - 2;
    }
  }
}
console.log(steps(10, 'desc'));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers