Skip to content

Instantly share code, notes, and snippets.

View DavidMellul's full-sized avatar

David Mellul DavidMellul

View GitHub Profile
const PRECISION = 0.2; // Often called a Delta
function isValid(time) { // Ensures 1 second has elapsed
const expected = 1;
// We only assert this : (expected - precision) <= time <= (expected + precision)
return (expected - PRECISION <= time) && (expected + PRECISION >= time);
}
console.log(isValid(1.105));
let x = 5;
let expected = 8;
console.log('Content of variable x is: ' + x + ', and expected is ' + expected);
// => Content of variable x is: 5, and expected is 8
let x = 5;
let expected = 8;
console.log(`Content of variable x is: ${x} and expected is ${expected}`);
// => Content of variable x is: 5, and expected is 8
let x = [1,2,3,4,5];
let y = [];
for(let i = 0; i < x.length; i ++)
y[i] = x[i]*2;
console.log(y);
// => [2,4,6,8,10]
let x = [1,2,3,4,5];
let y = x.map ( element => element*2 );
console.log(y);
// => [2,4,6,8,10]
let x = [1,2,3,4,5];
let y = [];
for(let i = 0; i < x.length; i++)
if(x[i] % 2 == 0)
y.push(x[i]*2);
else
continue;
console.log(y);
let x = [1,2,3,4,5];
let y = x.filter( element => element % 2 == 0).map(element => element*2);
console.log(y);
// => [4,8]
var OPTIONS = {
'GRAYSCALE': 1, 'SEPIA': 2, 'HIGH-RES': 3, 'LOW-RES': 4
};
function setCameraSettings(options) {
if(options.includes(OPTIONS['GRAYSCALE']))
console.log('GRAYSCALE activated');
if(options.includes(OPTIONS['SEPIA']))
console.log('SEPIA activated');
var OPTIONS = {
'GRAYSCALE': 1, 'SEPIA': 2, 'HIGH-RES': 4, 'LOW-RES': 8
};
function setCameraSettings(options) {
if( options & OPTIONS['GRAYSCALE'] )
console.log('GRAYSCALE activated');
if( options & OPTIONS['SEPIA'] )
console.log('SEPIA activated');
// Hypothetical NLP function - ES6 includes used
function isTextFunEnough(text) {
if(text.length == 0) {
return false;
}
else if(text.includes('lol')) {
if(text.includes('angry'))
return false;
else
return true;