This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const addUp = (...numbers) => { | |
var sum = 0; | |
numbers.forEach(function(item) { | |
sum = sum + item; | |
}); | |
return sum; | |
} | |
console.log(addUp(1, 5, 6)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Class User { | |
public $first_name; | |
public $last_name; | |
public $email; | |
public function setUserData($first_name, $last_name, $email){ | |
$this->first_name = $first_name; | |
$this->last_name = $last_name; | |
$this->email = $email; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enter Mongo | |
Access `C:\Program Files\MongoDB\Server\4.2\bin` via CMD | |
// Enter mongo mode | |
mongo | |
// Show databases | |
show dbs | |
// Create and switch to database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Database | |
{ | |
public $host = DB_HOST; | |
public $username = DB_USER; | |
public $password = DB_PASS; | |
public $dbname = DB_NAME; | |
public $link; | |
public $error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sql = 'SELECT * FROM people'; | |
$result = $db->query($sql); | |
$numrows = $result->rowCount(); | |
?> | |
<table> | |
<tr> | |
<th>First name</th> | |
<th>Last name</th> | |
<th>Gender</th> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
$con = new PDO('mysql:host=127.0.0.1;dbname=db_name','db_user','myPass'); | |
} catch (PDOException $e) { | |
die("Database connection failed."); | |
} | |
?> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addArrayMembers(arr) { | |
sum = 0; | |
arr.forEach(function(el, index) { | |
return sum = sum + arr[index]; | |
}); | |
return sum; | |
} | |
var arr = [1, 3, 5, 7]; | |
addArrayMembers(arr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fact() { | |
arr = []; | |
var n = arguments[0]; | |
if (n == 0) { | |
arr.push(1); | |
} else { | |
for (i = 1; i <= n; i++) { | |
arr.push(i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(){ | |
// Create an array from the functions arguments object | |
// then sum the array members using reduce | |
var sum = Array.from(arguments).reduce(function(a, b){ | |
return a + b; | |
}); | |
console.log(sum); | |
} | |
// You can now add as many numbers as you like | |
// just by passing them to the function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(){ | |
var sum = 0; | |
// Use "the arguments object" to add up all the arguments | |
// passed to a function | |
for (i=0; i<arguments.length; i++){ | |
var sum = sum + arguments[i]; | |
} | |
console.log(sum); | |
} | |
// You can now add as many numbers as you like |
NewerOlder