From 8a61c06b2c991d88c78a04b127ea4495b35263db Mon Sep 17 00:00:00 2001 From: chase Date: Mon, 18 Feb 2019 15:29:33 -0600 Subject: [PATCH] WIP: added flip-bool.js --- src/flip-bool.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/flip-bool.js diff --git a/src/flip-bool.js b/src/flip-bool.js new file mode 100644 index 00000000..47968d12 --- /dev/null +++ b/src/flip-bool.js @@ -0,0 +1,31 @@ +/* eslint prefer-spread:0 */ +export default flipBool + +/** + * Original Source: + * https://github.com/eggheadio-github/stack-overflow-copy-paste/issues/251 + + * This method will take a boolean value and reverse its value. + * + * @param {bool} boolArg - the bool that will be mutated + * @return {bool} boolArgv - the bool that was mutated + * + * Takes a bool value and checks to see if it's data type is boolean. If true, + * it will reverse the value of the passed boolean and return that value. If + * false, it returns a string with the value 'boolean expected'. + */ + +function flipBool(boolArg) { + + if (typeof (boolArg) === 'boolean') { + + if (boolArg === true) { + boolArg = false + } else { + boolArg = true + } + return boolArg + } else { + return 'boolean expected' + } +}