Create a gist now

Instantly share code, notes, and snippets.

@martinaglv /01.js
Last active May 28, 2018

Embed
What do these functions do?
function whatDoesItDo(val){
return val ? 1 : 2;
}
function whatDoesItDo(param){
return { blue:"#0000ff", green:"#00ff00", red:"#ff0000" }[param];
}
function whatDoesItDo(color){
if (color !== 'blue' || color !== 'green') {
color = 'red';
}
return color;
}
function whatDoesItDo(arr){
return arr.filter(function(elem, pos) {
return arr.indexOf(elem) == pos;
});
};
function whatDoesItDo(arr){
return arr.reduce(function(s, n){ return s + n; }, 0);
}
function whatDoesItDo(arr){
return arr.map( function(x){ return x*2; });
}
function whatDoesItDo(mood){
return mood && "I like this" || "I don't like this";
}
function whatDoesItDo(str){
return str.split('').reverse().join('')
}
function whatDoesItDo(){
return document.querySelectorAll('*').length;
}
function whatDoesItDo(arr){
return Math.max.apply(null, arr);
}
function whatDoesItDo(arr){
return arr.slice(0).sort();
}
function whatDoesItDo(num){
return Math.max(0, Math.min(10, num));
}
function whatDoesItDo(){
var values = [];
myBlock: {
values.push('1');
values.push('2');
break myBlock;
values.push('3');
}
values.push('4');
return values.join(',');
}
function whatDoesItDo(){
return Array(4).join("lol" - 2) + " Batman!";
}
function whatDoesItDo(str){
return str.bold().italics();
}
function whatDoesItDo(str){
return /^\d{3,}$/.test(str);
}
function whatDoesItDo(num){
return this + num;
}
whatDoesItDo = whatDoesItDo.bind(10);
function whatDoesItDo(){
return (![]+[])[+[]]+(![]+[])[+!+[]]+
([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]];
}
@vijaybritto

This comment has been minimized.

Show comment
Hide comment
@vijaybritto

vijaybritto Aug 26, 2014

do you have an explanation for the 18th? what do you call that in english ? :)

do you have an explanation for the 18th? what do you call that in english ? :)

@cdtapay

This comment has been minimized.

Show comment
Hide comment
@cdtapay

cdtapay Sep 5, 2014

It is way to play with typecasting. Check http://patriciopalladino.com/blog/2012/08/09/non-alphanumeric-javascript.html and https://github.com/aemkei/jsfuck/blob/master/jsfuck.js to understand how that technique works.

cdtapay commented Sep 5, 2014

It is way to play with typecasting. Check http://patriciopalladino.com/blog/2012/08/09/non-alphanumeric-javascript.html and https://github.com/aemkei/jsfuck/blob/master/jsfuck.js to understand how that technique works.

@stevematdavies

This comment has been minimized.

Show comment
Hide comment
@stevematdavies

stevematdavies Nov 22, 2014

15 has been depreciated (bold() and italics())

15 has been depreciated (bold() and italics())

@Gavin-Steele

This comment has been minimized.

Show comment
Hide comment
@Gavin-Steele

Gavin-Steele Dec 8, 2014

Would be great to follow up the quiz with an explanation of some of these.
Thanks

Would be great to follow up the quiz with an explanation of some of these.
Thanks

@prasanthtr575

This comment has been minimized.

Show comment
Hide comment
@prasanthtr575

prasanthtr575 May 20, 2015

Great hints for Javascript. Please provide some for operations on array of objects such as sorting, filtering

Great hints for Javascript. Please provide some for operations on array of objects such as sorting, filtering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment