Skip to content

Instantly share code, notes, and snippets.

View DavidMellul's full-sized avatar

David Mellul DavidMellul

View GitHub Profile
function Champion(category = 'Champion') {
this.category = category;
this.sayHi = function() { console.log(`Hey, a ${this.category} is here`) };
};
function Warrior() {
Champion.call(this,'Warrior');
}
function Dwarf() {
function Champion(category = 'Champion') {
this.category = category;
};
function Warrior() {
Champion.call(this,'Warrior');
}
function Dwarf() {
Champion.call(this,'Dwarf');
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// Stuff
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// Using ES6 arrow functions
// Returns true if all even numbers doubled from @numbers are above 5
function doubleEvenNumbers(numbers) {
return numbers
.filter(x => x % 2 == 0) // Odd numbers removed
.map(x => x*2) // Even numbers doubled
.every(x => x > 5); // Are they all above 5 ?
}
// Using ES6 arrow functions
// Returns true if all even numbers doubled from @numbers are above 5
function doubleEvenNumbersES6(numbers) {
return numbers.filter(x => x % 2 == 0).map(x => x*2).every(x => x > 5);
}
console.log(doubleEvenNumbersES6([3,4,5,6]))
// => True, because doubled array is [8,12]
// Hypothetical NLP function - ES6 includes used
function isTextFunEnough(text) {
if(text.length == 0 || text.includes('angry'))
return false;
return text.includes('lol');
}
console.log(isTextFunEnough('This article is so epic lol') ? 'Definitely fun, LMAO':'Not very funny...');
// => Definitely fun, LMAO
// 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;
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');
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');
let x = [1,2,3,4,5];
let y = x.filter( element => element % 2 == 0).map(element => element*2);
console.log(y);
// => [4,8]