Skip to content

Instantly share code, notes, and snippets.

@saveroo
Last active December 14, 2020 01:25
Show Gist options
  • Save saveroo/8d5b15f1433c51387b429d770ba5aad3 to your computer and use it in GitHub Desktop.
Save saveroo/8d5b15f1433c51387b429d770ba5aad3 to your computer and use it in GitHub Desktop.
Seeking Truth With Javascript
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