Last active
October 28, 2019 15:28
-
-
Save giteden/94e703fb17c76a867f593df3f79f49bd to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
const Accordion = props => { | |
return props.info.map(item =>{ | |
return ( | |
<div> | |
Code, code, code... | |
</div> | |
) | |
}) | |
} | |
Accordion.propTypes = { | |
// Check if the standard deviation of the lengths of the pieces of content is too great | |
infoStd: props => { | |
// calculate std | |
const lengths = props.info.map(item => item.content.length); | |
const avg = lengths.reduce((sum ,item) => sum + item) / lengths.length; | |
const sqrSum = lengths.reduce((sum, item) => sum + Math.pow((item - avg),2)); | |
const infoStd = Math.sqrt(sqrSum) / lengths.length; | |
// validate (30 is sort-of an arbitrary number that seems right to me) | |
if (infoStd > 30) { | |
return new Error('The items presented in the accordion differ too much in length. Consider using a different component.'); | |
} | |
} | |
} | |
export default Accordion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment