From e0d80db96bcfb6786a4c789c3bc0cf039835c9c8 Mon Sep 17 00:00:00 2001 From: Kiner Shah Date: Sun, 26 May 2019 16:27:23 +0530 Subject: [PATCH 1/3] Update README.md --- JS/README.md | 225 ++++++++++++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 111 deletions(-) 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;` From 33689d28a2584711019fcd010d8e6acbd8d75880 Mon Sep 17 00:00:00 2001 From: Kiner Shah Date: Sun, 26 May 2019 16:29:10 +0530 Subject: [PATCH 2/3] Update README.md --- twitterbot/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/twitterbot/README.md b/twitterbot/README.md index 220f7bf..9ea180d 100644 --- a/twitterbot/README.md +++ b/twitterbot/README.md @@ -1,5 +1,5 @@ -#Reference for using `twit` -##Dependencies +# Reference for using `twit` +## Dependencies
 // 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": {    

From e82aa0e15d09511a91c1485720a1747f734b068f Mon Sep 17 00:00:00 2001
From: Kiner Shah 
Date: Mon, 1 Jul 2019 20:09:37 +0530
Subject: [PATCH 3/3] Update README.md

Fixed markdown
---
 npm-tutorial/README.md | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

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 
 ```
 Or, go to [NPM Registry](https://npmjs.com)
 
-##Installing an npm module
+## Installing an npm module
 ```
 $ npm install 
 ```
@@ -35,7 +35,7 @@ $ npm install express -g
 ```
 _Note:_ NPM modules (If installed locally) should be installed in the directory of the node instance, or the npm module.
 
-##Uninstall an npm module
+## Uninstall an npm module
 ```
 $ npm uninstall 
 ```
@@ -44,7 +44,7 @@ _Example:_
 $ npm uninstall express
 ```
 
-##Updating a module
+## Updating a module
 ```
 $ npm update 
 ```
@@ -53,12 +53,12 @@ _Example:_
 $ npm update express
 ```
 
-##Creating your own NPM module
-###Creating an account in the NPM registry
+## Creating your own NPM module
+### Creating an account in the NPM registry
 1. Go to [NPM Registry](https://npmjs.com) and create an account
 2. Remember the username and password
 
-###Initializing your module
+### Initializing your module
 1. Create a directory with the name of the module you intend to create; for e.g. vatsal-module-1.
 2. Navigate to the folder you've made.
 3. Start the node/ npm REPL in the folder.
@@ -67,7 +67,7 @@ $ npm update express
 6. Unless you want to change anything, keep the values default as mention between the parentheses.
 7. Done! You've initialized your first node module!
 
-###Writing your module
+### Writing your module
 + We will be writing a module which prints the current date and time.
 + After initializing your module, if not done already, navigate to the module's directory.
 + Create a file named index.js.
@@ -87,11 +87,11 @@ console.log (date.getDate()  + "/" + // get Today's Date
 			(date.getYear - 100));
 ```
 
-###Running the module
+### Running the module
 + Navigate to the directory of your module
 + Type into the node REPL: `$ npm start`
 
-###Publish your module
+### Publish your module
 + Change the version number to desired number in package.json. **Do not change anything else**.
 + Make sure you have an account on [NPM Registry](https://npmjs.com).
 + Type into the REPL: