Last active
December 14, 2020 01:25
-
-
Save saveroo/8d5b15f1433c51387b429d770ba5aad3 to your computer and use it in GitHub Desktop.
Seeking Truth With Javascript
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 truthSeeking = (characteristics = ['He', 'Is', 'One'], aspectsOrCases = [true, true, true]) => { | |
const | |
aspectCovered = [], | |
characteristicCovered = []; | |
const iterate = (cases, storage) => {for (let i = 0; i < cases.length; i++) { | |
if(cases[i]) storage.push(cases[i]) | |
else iterate(cases); | |
}} | |
iterate(characteristics, characteristicCovered); | |
iterate(aspectsOrCases, aspectCovered); | |
const | |
areAllAspectCovered = () => | |
aspectCovered.filter(aspect => aspect).length | |
=== | |
aspectsOrCases.length, | |
isCharacteristicIsMatch = () => | |
characteristicCovered.length | |
=== | |
characteristics.length | |
return { | |
characteristics: [...characteristicCovered], | |
aspectCovered: areAllAspectCovered() | |
? 'All of them' | |
: 'Not all of them', | |
conclusion: isCharacteristicIsMatch() | |
&& areAllAspectCovered() | |
? 'Yes, He is the one' | |
: 'Keep seeking' | |
} | |
} | |
const isHeTheOneQuestionMark = truthSeeking( | |
['He', 'is', 'One'], | |
[1+1 === 2, 1+2 === 3, 2+1 === 3]); | |
console.log(isHeTheOneQuestionMark) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment