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
// this is a big array of 76 items I need to split into groups of 10 | |
const hugeArray = Array.from({ length: 76 }, (_, i) => i); | |
function chunkify(array, chunkSize = 10) { | |
// make a new array | |
const chunks = Array.from( | |
// give it however many slots are needed - in our case 8 | |
// 1-7 with 10 items, and 8th slot will have 6 | |
{ length: Math.ceil(array.length / chunkSize) }, | |
// this is a map function that will fill up our slots |
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
The BOM (Browser Object Model) consists of the objects navigator, history, screen, location and | |
document which are children of window. | |
In the document node is the DOM (Document Object Model), | |
the document object model, which represents the contents of the page. | |
You can manipulate it using javascript. |
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
var calculationPromise = new Promise(function(resolve,reject){ | |
setTimeout(function() { | |
resolve(1+1); | |
}, 1000) | |
}); | |
var calculationPromise2 = new Promise(function(resolve,reject){ | |
setTimeout(function() { | |
resolve(2+2); |
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
var foo = 10 + '20'; | |
console.log(0.1 + 0.2 == 0.3); // false | |
console.log((1/10)+(2/10)); // 0.30000000000000004 | |
var add1 = function(x,y) { | |
return x+y; | |
} | |
var add = function(x) { | |
return function(y) { return x + y; }; | |
} | |
var addWithTwoArgs = add1(2,5); //7 |
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 Apple (type) { | |
this.type = type; | |
this.color = "red"; | |
this.getInfo = getAppleInfo; | |
} | |
// anti-pattern! keep reading... | |
function getAppleInfo() { | |
return this.color + ' ' + this.type + ' apple'; | |
} |
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
let calculate = (no1, no2, operation) => { | |
let result; | |
switch (operation) { | |
case 'add': | |
result = no1 + no2; | |
break; | |
case 'subtract': | |
result = no1 - no2; | |
break; | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<script> | |
function show(){ | |
var i, no, fact; | |
fact=1; | |
no=document.getElementById("num").value; | |
for(i=1; i<=no; i++) |