Last active
August 1, 2021 12:47
-
-
Save AbudiMutamba/148bbbf5442e0de3372c4a1e0f9b547d to your computer and use it in GitHub Desktop.
Algorithm that validates a false value.
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
//There are only six falsey values in JavaScript: undefined, null, NaN, 0, "" (empty string), and false of course. | |
/** | |
* @fuction determineFalsy | |
* @param {value} input | |
* @returns false | |
*/ | |
let determineFalsy = (input) => { | |
if (!input) return true | |
return false | |
} | |
module.exports = determineFalsy |
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
const determineFalsy = require('../../falsy') | |
//Determining null of falseValue | |
test('Determining null of falseValue', () =>{ | |
expect(determineFalsy()).not.toBeNull() | |
}); | |
//Determining if underfined is a falsy value | |
test('Determining if underfined is a falsy value', () =>{ | |
expect(determineFalsy(undefined)).toBe(true); | |
}); | |
//Determining if value is NaN of falseValue | |
test('Determining if value is NaN of falseValue', () =>{ | |
expect(determineFalsy(NaN)).toBe(true) | |
}); | |
//Determining if 0 is afalseValue | |
test('Determining if 0 is afalseValue', () =>{ | |
expect(determineFalsy(0)).toBe(true) | |
}); | |
//Determining if empty string is a falsy value | |
test('Determining if empty string is a falsy value', () =>{ | |
expect(determineFalsy("")).toBe(true) | |
}); | |
//Determining if string is a falsy value | |
test('Determining if string is a falsy value', () =>{ | |
expect(determineFalsy("abudi")).not.toBe(true) | |
}); | |
//Determining if value is false | |
test('Determining if value is false', () =>{ | |
expect(determineFalsy(1)).not.toBe(true) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment