diff --git a/JS/README.md b/JS/README.md index 879ae72..5eeda83 100644 --- a/JS/README.md +++ b/JS/README.md @@ -1,187 +1,190 @@ # JS CheatSheet -##Comments -###Single Line Comment -> // +## Comments +### Single Line Comment +`// This is a single line comment ` -###Multi Line Comment -> /* */ +### Multi Line Comment + /* This is a + multi-line comment */ -##Variables -> var variable = 1; +## Variables +`var variable = 1;` -##Operators -###Assignment operators +## Operators +### Assignment operators -- x = y : `x = y` -- x = x + y : `x += y` -- x = x - y : `x -= y` -- x = x * y : `x *= y ` -- x = x / y : `x /= y` +- `x = y` +- `x += y`, equivalent to `x = x + y` +- `x -= y`, equivalent to `x = x - y` +- `x *= y`, equivalent to `x = x * y` +- `x /= y`, equivalent to `x = x / y` -###Logical operators +### Logical operators -- Equal value and type : `===` -- Not equal value or not equal type : `!==` -- Greater than or equal to : `>=` -- Less than or equal to : `<=` +- Equal value and type: `===` +- Not equal value or not equal type: `!==` +- Greater than or equal to: `>=` +- Less than or equal to: `<=` -####Ternary -- shorthand for a conditional : `?` - > condition ? 'do this if true': 'do this if false' +#### Ternary -- shorthand for a conditional : `?` + `condition ? 'do this if true': 'do this if false'` -Example : -> var canDrink = age > 21 ? 'Go drink!' : 'Sorry you're too young!' +Example: `var canDrink = age > 21 ? 'Go drink!' : 'Sorry you're too young!';` - Returns true if both are true : `('comparision1' && 'comparison2')` - Returns true if at least one is true : ` ('comparison1' || 'comparison2') ` - Returns opposite of boolean value : `!('comparison')` -##Arrays +## Arrays -> var arrayName = ['add text', 23, true]; -> var arrayName2 = []; + var arrayName = ['add text', 23, true]; + var arrayName2 = []; -###Access array items +### Access array items Item in the ith position of the array `arrayName[i]` -###Add to array -Adds to end, back of the line -> arrayName2.push('what you want to add'); +### Add to array +Adds to end, back of the line: `arrayName2.push('what you want to add');` Adds the front, un is bad - the items are cutting everyone to get to the front ->arrayName2.unshift('new addition', 'another new additon'); -###Remove from array +`arrayName2.unshift('new addition', 'another new additon');` -Last item pops off -> arrayName2.pop(); +### Remove from array -First item is removed and all others shift up in line -> arrayName2.shift(); +Last item pops off: `arrayName2.pop();` +First item is removed and all others shift up in line: `arrayName2.shift();` -###Splicing arrays -> arrayName[i].splice(j,k,x); +### Splicing arrays + +`arrayName[i].splice(j,k,x);` where - - - i is the array index (if you have an array inside an array), - - j is the item index - - k is the number of items to remove - - x is items to add - + - `i` is the array index (if you have an array inside an array), + - `j` is the item index + - `k` is the number of items to remove + - `x` is items to add -###Rename item in an array -> arrayName[i] = 'new value' +### Rename item in an array -where i is the index of the item being replaced +`arrayName[i] = 'new value'` +where `i` is the index of the item being replaced -##If Else -
if (condition) {
- console.log('do this if true');
-} else {
- console.log('do this if false');
-}
+## If-Else
-##For loop
+ if (condition) {
+ console.log('do this if true');
+ } else {
+ console.log('do this if false');
+ }
-Starting value of i : `i = 0 `
-How many times loop will run : `i !==10`
-How to increment i after loop, adds 1 to i : `i++`
- Will increment by the # specified : `i+=#`
+## For loop
+ for (var i = 0; i !== 10; i++ ) {
+ console.log(i);
+ }
-for (var i = 0; i !== 10; i++ ) {
- console.log(i);
-}
+ - Starting value of `i`: `i = 0 `
+ - How many times loop will run: `i !== 10`
+ - How to increment `i` after loop, adds 1 to `i`: `i++`
+ - Will increment by the # specified: `i += #`
-##While loop
+## While loop
-while (condition) {
- console.log('do this');
-}
-
- Will run until condition is false, could run zero times
+ while (condition) {
+ console.log('do this');
+ }
-##Do while loop
+Will run until condition is false, could run zero times.
-do {
- console.log('do something')
-} while (condition);
+## Do-while loop
+
+ do {
+ console.log('do something')
+ } while (condition);
- Will run at least once and continues to run until condition is false
+ Will run at least once and continues to run until condition is false.
-##Objects
+## Objects
-var objectName = {
- property1: "can be text",
- property2: ['or', 'an', 'array'],
- property3: true,
- property4: {
- subProperty1: "amanda",
- subProperty2: 10,
- }
-}
+ var objectName = {
+ property1: "can be text",
+ property2: ['or', 'an', 'array'],
+ property3: true,
+ property4: {
+ subProperty1: "amanda",
+ subProperty2: 10,
+ }
+ }
Access items in an object (dot notation):
->console.log(objectName.property1);
->console.log(objectName.property2[2]);
+
+ console.log(objectName.property1);
+ console.log(objectName.property2[2]);
Object starting with blank
->var newObject = new Object();
-newObject.property1 = "can add text";
-newObject.property2 = [1,2,3,4];
-newObject.property3 = {
- subProperty1: 'new text',
- subProperty2: 10,
- subProperty3: [2,4,6]
-}
+ var newObject = new Object();
-> console.log(newObject);
+ newObject.property1 = "can add text";
+ newObject.property2 = [1,2,3,4];
+ newObject.property3 = {
+ subProperty1: 'new text',
+ subProperty2: 10,
+ subProperty3: [2,4,6]
+ }
+ console.log(newObject);
-##Functions
-function functionName(property) {
- return property;
-}
+## Functions
+ function functionName(property) {
+ return property;
+ }
-###Call a function
-> functionName(enterProperty);
+### Call a function
-###Sorting from smallest to largest
+`functionName(enterProperty);`
-arrayName.sort(function(a, b) {
- return a - b
-});
-Change to b - a for largest to smallest
+### Sorting from smallest to largest
+ arrayName.sort(function(a, b) {
+ return a - b
+ });
-###is NaN
+Change to `b - a` for largest to smallest
-function isNaN(testValue) {
- return Number.isNaN(Number(testValue));
-}
+### is NaN
-##Random number generator
+ function isNaN(testValue) {
+ return Number.isNaN(Number(testValue));
+ }
+
+
+## Random number generator
Generates number between 0 and 1, multiply to get whole numbers
->Math.random()
+
+`Math.random()`
Rounds down to nearest whole number
->Math.floor(number to round down);
+
+`Math.floor(floating_point_number_to_round_down);`
Round to two decimal places
->Math.round(NumberWithMoreDecimals * 100) / 100;
+
+`Math.round(NumberWithMoreDecimals * 100) / 100;`
diff --git a/npm-tutorial/README.md b/npm-tutorial/README.md
index 069c839..055dcc2 100644
--- a/npm-tutorial/README.md
+++ b/npm-tutorial/README.md
@@ -1,26 +1,26 @@
-#NPM - Node's package manager
+# NPM - Node's package manager
-##Checking the npm version
+## Checking the npm version
In order to check npm's version, type into the node repl:
```
$ npm --version
4.1.2
```
-##Installing and upgrading NPM
+## Installing and upgrading NPM
npm comes pre - installed with node.
In order to update it, simply type into the node repl:
```
$ npm install npm -g
```
-##Searching for npm modules
+## Searching for npm modules
```
npm search // Dependencies ========================= var @@ -8,7 +8,7 @@ var var Twitter = new twit(config);-##For Retweet +## For Retweet
// RETWEET BOT ==========================
@@ -46,14 +46,14 @@ var retweet = function() {
});
}
-###Using Retweet
+### Using Retweet
// grab & retweet as soon as program is running... retweet(); // retweet in every 50 minutes setInterval(retweet, 3000000);-##For Favorite +## For Favorite
// FAVORITE BOT====================
@@ -99,7 +99,7 @@ function ranDom (arr) {
return arr[index];
};
-##Complete Retweet + Favourite
+## Complete Retweet + Favourite
// Dependencies =========================
@@ -190,7 +190,7 @@ function ranDom (arr) {
return arr[index];
};
-##Configuration for twitter
+## Configuration for twitter
/** TWITTER APP CONFIGURATION
@@ -201,7 +201,7 @@ module.exports = {
access_token_secret: ''
}
-##Scripts
+## Scripts
{
"scripts": {