Cheat Sheets for the Struggling Souls
Let me cut to the chase and just say it. If you stop coding, you will forget!
As I reach my second to last phase of my bootcamp, I am realizing that my blood, sweat, and tears of work in the first two phases is slowly fading away. Even if I am coding in a secondary language(Ruby), I’m quite rusty in my oh-so-called primary language(Javascript). Although the logic being used to solve the problems will be present in all languages, I am forgetting what kind of methods, operators even existed.
Fear Not! There are plenty of refreshers available to you online, including mine. I will be covering some basic Javascript.
- Arrays
- Operations
- If/Else Statements
- String
- Regular Expression
- Math
- a special present!
Arrays
let group = [“Leslie”, “Apoorva”, “Zach”]
let team = [“Yearim”, “Alec”, “Mari”]
let partners = [“Yi”, “Lex”, “Nathan”]
Array Methods:
- pop() // removes the last element in an array, think of “Pop off”
group.pop() // [“Leslie”,”Apoorva”] *Bye Zach!
- push() // adds a new element to the end of an array, think of “Push on”
group.push(“Zach”)//[“Leslie”,”Apoorva”,”Zach”] *Zach is back
- shift() // removes the first element in an array
group.shift() // ["Apoorva”, "Zach"] *I'm leaving!
- unshift() //adds a new element to the beginning of an array
group.unshift(“Leslie”)//[“Leslie”,”Apoorva”,”Zach”] *I'm back
- slice(start, end) //returns a copy of an array from start to end of an index
partners.slice(1) // ["Lex", "Nathan"]
partners.slice(-1) // ["Nathan"]
partners.slice(0, 1) // ["Yi"]
partners.slice(1, -1) // ["Lex"] - splice(where, how many?*, item list*) // add elements (where, how many to remove, element list) * is optional
team.splice(1, 0, “Apoorva”, “Zach”) // ["Yearim", "Apoorva", "Zach", "Alec", "Mari"]
- sort() //sorts element alphabetically
team.sort() // [“Alec”,”Mari”,”Yearim”]
- sort() //numeric sort
let nums = [1, 3, 6, 2, 5, 4]
sort((a, b) => a - b)// [1,2,3,4,5,6]
Operators
Comparison Operators:
== Equal to
=== Equal Value and Type
!= Not Equal to
!==Not Equal Value and Type
<=, >= less or equal, greater or equal
Logical Operators:
&& logical and
|| logical or
! logical not
If/Else Statements
if (condition1 is true) {
// run this code
} else if (condition2 is true) {
// run this
} else {
//do this
}
Switch Statements
switch (phase) {
case 1: // if (phase == 1)
teacher = "Ix";
break;
case 2: // if (phase == 2)
teacher = "Louis";
break;
case 3: // if (phase == 3)
teacher = "Dakota";
break;
case 4: // if (phase == 4)
teacher = "Ix";
break; default: // else...
teacher = "Adam?";
}
String Methods
let string = “Potatoes”
let sentence = “Potatoes Underground”
charAt() //returns a character at the specified index string.charAt(0) //”P”
split() //splits a string into an array of string, pattern provided in the parameter. sentence.split(“ ") //[“Potatoes”,”Underground”]
replace() // find and replace specific text (once only, if a string)sentence.replace(“Potatoes”, “Bananas”) // “Bananas Underground”
string.replace(“o”, “0”) // “P0tatoes”
string.replace(/o/g, “0”) // “P0tat0es”
startsWith() //checks if string starts with a characters specified string string.startsWith(“Pot”) //true
endsWith() //checks if string ends with a characters specified string string.endsWith(“toes”) //true
match(regex) //retrieves matches of string against the inserted stringstring.match(/toe/) //[“toe”]
REGEX
I know this scares a lot of y’all. It scares me too, but we can’t be running away from it all the time!
Brackets
[.?!] // find any characters in the brackets
[^.?!] //find any characters not in the brackets
[0–9] //find any digits from 0–9
[A-Za-z] //find any character from uppercase A -Z to lowercase a-z
Pattern Modifiers
i // case insensitive
gm // global matching, multiple matches
Math Methods
abs(n) // return absolute value of n Math.abs(-5) // 5
ceil(n) // value of n rounded up to the nearest integer
floor(n) // value of n rounded down to the nearest integer
max(x, y, z, n) // return the number with highest value Math.max(8, 4, 3, 6) //8
min(x, y, z, n) //returns the number with lowest value
random() //returns a random number between 0 and 1
BONUS!!!!!
Don’t worry, we are almost there!
A lot of the times when we drive/navigate, I realize that some of my cohort-mates are missing out on some shortcuts, whether by choice or unawareness! So allow me to share some of my tricks!
*these are based on macs on the Browser
- cmd + // zoom in
- cmd- // zoom out
- cmd 0 // original
- ctrl tab // switch tabs within the window
- cmd tab // switch through all opened apps
On visual studio code
- shift + command + p // show command palette
- option + d // multi select
- option up/down arrow // move line up or down
- command + / // toggling comment
- command + n // new file
- command + s // save file
- command + w // close current window
- command up/down arrow // beginning or end of file
- control + ` // open vs code terminal
Terminal
- control + l // clear terminal
- control + u // delete everything from cursor position to the beginning of the line
- control + a // move cursor to the beginning
Git Command
Have you ever cloned a lab instead of forking it and now you can’t push it up? Well, here are some commands that can save you from that situation!
First, go to the repo and fork → copy the SSH
git remote -v *check that the origin isn't your github
git remote remove origin
git remote add origin *copy and paste the SSH
git remote -v *check your work and celebrate :D
If you want to redo a lab that you forked without physically deleting all the work?
git reset --soft HEAD~1 *remove last commit from the current branch
git restore *as an alternative to --soft you can do this
git reset --hard HEAD~1 you will lose all uncommited changes and all untracked files
Congratulations!
You actually scrolled down to the bottom of the article! Thanks for sticking around to the end. I hope this was helpful to you in some way!!!