Back to Freecodecamp

Step 108

curriculum/challenges/english/blocks/learn-introductory-javascript-by-building-a-pyramid-generator/660f4e74f7fd3f4a99ac2e50.md

latest1.7 KB
Original Source

--description--

Arrays also have a .shift() method. This will remove the first element of the array, unlike .pop() which removes the last element. Here is an example of the .shift() method:

js
const numbers = [1, 2, 3];
numbers.shift();

The numbers array would be [2, 3].

Directly below your numbers array, declare a shifted variable and assign it the result of calling .shift() on the numbers array. On the next line, log the shifted variable to the console.

--hints--

You should use const to declare a shifted variable.

js
assert.match(__helpers.removeJSComments(code), /const\s+shifted/);

You should call .shift() on your numbers array.

js
assert.deepEqual(numbers, [5, 2, 3]);

You should assign the result of your .shift() call to your shifted variable.

js
assert.equal(shifted, 1);

You should log your shifted variable.

js
assert.match(__helpers.removeJSComments(code), /console\.log\(\s*shifted\s*\)/);

--seed--

--seed-contents--

js
const character = "#";
const count = 8;
const rows = [];

function padRow(rowNumber, rowCount) {
  return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}

// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
  rows.push(padRow(i, count));
}*/

/*while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}*/

/*for (let i = count; i > 0; i--) {
  rows.push(padRow(i, count));
}*/

--fcc-editable-region--
const numbers = [1, 2, 3];


const unshifted = numbers.unshift(5);
console.log(unshifted);
console.log(numbers);
--fcc-editable-region--

let result = ""

for (const row of rows) {
  result = result + row + "\n";
}

console.log(result);