Month: January 2023

  • Looping through js objects with “for in”

    To “map” through a js object use “for in” First we get each item in the object and call it ‘person’ to make it easier to read. Then loop through it’s data to populate the array. In our example “data” is the key (eg. “name”) and “person[data] is the value (eg. “Mark”). We also manually…

  • Basic unit testing with Jest

    Let’s say for example we have a back end function that checks if you are under age from a user’s date of birth. First we load that function: Then we set up some test data, like so: We then run the function using the test datas. In our example the function will return some validation…

  • Full size background image

    Background-size cover makes the image cover the whole screenBackground-position center centers the imageBackground-attachement fixed makes it so the image doesn’t move when you scroll down the page.

  • Using Reduce

    Reduce is used somewhat similar to ‘map’ Zero is set as the initial value and then it goes through the array and adds each value (in this example the currentScore) to the totalScore which becomes the new ‘previousScore’. Here’s a more useful example:

  • Checking a video to play it

    This was from a long time ago. I think it had something to do with browser compatibility or device compatibility. Leaving it here in case it’s useful in the future.

  • How to conditionally wrap an element in React

    The ConditionalWrap component checks the condition (in this example the element.url) and if it exists put the wrapper around the children, otherwise just render the children. The wrapper in this example is a link. You can put whatever content you want where the comment is to be put inside the link.

  • How to undo a pushed merge in Git

    First use “git log –oneline” to find the commit that you want to go back to and copy it somewhere. Then use You are now reset back to a previous commit. To finish, do force push.