Created
December 10, 2013 23:30
-
-
Save skeggse/7902324 to your computer and use it in GitHub Desktop.
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
/** | |
* @param {Object.<string, boolean>} data | |
* @return {number} | |
*/ | |
function hello(data) { | |
var q = 0; | |
if (data.a) { | |
if (data.b && data.c) { | |
q = 1 | |
} else if (data.d) { | |
q = 2; | |
} else if (!data.b) { | |
throw new Error('nope'); | |
} else { | |
throw new Error('denied'); | |
} | |
} | |
return q; | |
} | |
/** | |
* @param {Object.<string, boolean>} data | |
* @return {string} | |
*/ | |
function q(data) { | |
try { | |
return hello(data) + ''; | |
} catch (err) { | |
return err.message; | |
} | |
} | |
/** | |
* @param {Object.<string, boolean>} data | |
* @param {string} expect | |
* @return {boolean} | |
*/ | |
function test(data, expect) { | |
var body = JSON.stringify(data) + ' === ' + JSON.stringify(expect); | |
var res = q(data) === expect; | |
console.log(body, res); | |
return res; | |
} | |
window['a'] = test({'a': true, 'b': true, 'c': true, 'd': true}, '1'); | |
window['b'] = test({'a': true, 'b': true, 'c': true, 'd': false}, '1'); | |
window['c'] = test({'a': true, 'b': true, 'c': false, 'd': true}, '2'); | |
window['d'] = test({'a': true, 'b': true, 'c': false, 'd': false}, 'denied'); | |
window['e'] = test({'a': true, 'b': false, 'c': false, 'd': true}, '2'); | |
window['f'] = test({'a': true, 'b': false, 'c': false, 'd': false}, 'nope'); | |
window['g'] = test({'a': false, 'b': false, 'c': false, 'd': false}, '0'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment