Last active
July 25, 2024 03:38
-
-
Save martinaglv/0cf3f564d9c31c053da5 to your computer and use it in GitHub Desktop.
What do these functions do?
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 whatDoesItDo(val){ | |
return val ? 1 : 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
function whatDoesItDo(param){ | |
return { blue:"#0000ff", green:"#00ff00", red:"#ff0000" }[param]; | |
} |
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 whatDoesItDo(color){ | |
if (color !== 'blue' || color !== 'green') { | |
color = 'red'; | |
} | |
return color; | |
} |
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 whatDoesItDo(arr){ | |
return arr.filter(function(elem, pos) { | |
return arr.indexOf(elem) == pos; | |
}); | |
}; |
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 whatDoesItDo(arr){ | |
return arr.reduce(function(s, n){ return s + n; }, 0); | |
} |
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 whatDoesItDo(arr){ | |
return arr.map( function(x){ return x*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
function whatDoesItDo(mood){ | |
return mood && "I like this" || "I don't like this"; | |
} |
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 whatDoesItDo(str){ | |
return str.split('').reverse().join('') | |
} |
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 whatDoesItDo(){ | |
return document.querySelectorAll('*').length; | |
} |
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 whatDoesItDo(arr){ | |
return Math.max.apply(null, 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 whatDoesItDo(arr){ | |
return arr.slice(0).sort(); | |
} |
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 whatDoesItDo(num){ | |
return Math.max(0, Math.min(10, num)); | |
} |
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 whatDoesItDo(){ | |
var values = []; | |
myBlock: { | |
values.push('1'); | |
values.push('2'); | |
break myBlock; | |
values.push('3'); | |
} | |
values.push('4'); | |
return values.join(','); | |
} |
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 whatDoesItDo(){ | |
return Array(4).join("lol" - 2) + " Batman!"; | |
} |
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 whatDoesItDo(str){ | |
return str.bold().italics(); | |
} |
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 whatDoesItDo(str){ | |
return /^\d{3,}$/.test(str); | |
} |
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 whatDoesItDo(num){ | |
return this + num; | |
} | |
whatDoesItDo = whatDoesItDo.bind(10); |
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 whatDoesItDo(){ | |
return (![]+[])[+[]]+(![]+[])[+!+[]]+ | |
([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]; | |
} |
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.
15 has been depreciated (bold() and italics())
Would be great to follow up the quiz with an explanation of some of these.
Thanks
Great hints for Javascript. Please provide some for operations on array of objects such as sorting, filtering
do you have an explanation for the 18th? what do you call that in english ? :)
head to jsfuck
it returns "fail"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
do you have an explanation for the 18th? what do you call that in english ? :)