Last active
March 13, 2017 01:03
-
-
Save porcoespinho/7f640c178a0aaee69c9642bd536cb227 to your computer and use it in GitHub Desktop.
Luis Vargas version of Improving runWithDebugger #2
This file contains hidden or 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
// Beasts challenge 1 | |
/** | |
* Your task is to rewrite runWithDebugger so it can take an optional array | |
* that contains any arguments you want to pass into the callback function. | |
You should be able to pass multiple arguments into the array. Here's an example. | |
function sayFullName(first, last) { | |
console.log(first + ' ' + last); | |
} | |
runWithDebugger(sayFullName, ['gordon', 'zhu']); // 'gordon zhu' | |
*/ | |
/* Original run with debugger | |
function runWithDebugger(ourFunction) { | |
debugger; | |
ourFunction(); | |
} | |
*/ | |
// My solution: | |
function runWithDebugger(ourFunction, inputArray) { | |
debugger; | |
ourFunction.apply(null, inputArray); | |
} | |
/** | |
* I use the apply method in my solution... | |
* The apply() method calls a function with a given this value and arguments | |
* provided as an array (or an array-like object). | |
* Syntax: fun.apply(thisArg, [argsArray]) | |
* Note: if the method is a function in non-strict mode code, | |
* null and undefined will be replaced with the global object | |
* Example: | |
function sayFullName(first, last) { | |
console.log(first + ' ' + last); | |
} | |
sayFullName.apply(null,['luis','vargas']); | |
*/ |
Hi Gordon, thanks for the feedback!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Luis. Can you save this file as a JavaScript file so that you get syntax highlighting? Also make sure to format consistently. For example, the indentation in line 23 is unusual.