Week 4-stop being so forgetful

Once again another batch of work I totally forgot to upload

Tutorials

Problem sets

Blog question 

With the array methods pop() / push() and shift() / unshift(), explain the difference between the returned value of each method and the resulting value of the array? Use an example piece of code with the Enlighter tool to support your description.

pop(): Remove an item from the end of an array

let cats = ['Bob', 'Willy', 'Mini'];

cats.pop(); // ['Bob', 'Willy']

push(): Add items to the end of an array

let cats = ['Bob'];

cats.push('Willy'); // ['Bob', 'Willy']

cats.push('Puff', 'George'); // ['Bob', 'Willy', 'Puff', 'George']

shift(): Remove an item from the beginning of an array

let cats = ['Bob', 'Willy', 'Mini'];

cats.shift(); // ['Willy', 'Mini']

unshift(): Add items to the beginning of an array

let cats = ['Bob'];

cats.unshift('Willy'); // ['Willy', 'Bob']

cats.unshift('Puff', 'George'); // ['Puff', 'George', 'Willy', 'Bob']

Link to an example of a site that is using an array of data that is presented on page. Describe what is in value of the array.

The YouTube comment section of each video uses an array of data to present the comments on the page. When you sort Newest first, it shows the end of the array which is the most recent comments. When you comment under a video, your comment is pushed onto the array. Your username, date, comment, likes/dislikes, and replies are stored into one comment.

Join the Conversation

1 Comment

  1. Good job keeping up! Your range array and reverse array functions work well. The longest username solution needs to be wrapped in a function though. And when you do, it will allow you to use fewer variables:

    function longestUser(arr) {
        var longest = arr[0]
        for (var i = 1; i < arr.length; i++) {
            if (arr[i].length > longest.length) {
                longest = arr[i]
            }
        }
        return longest
    }
    
Leave a comment

Your email address will not be published. Required fields are marked *

css.php