I have the following code in my React app that creates tags out of JSON data:const files = Object.values(gist.files);const tags = files.map((file) => {    let tag = file.language ? file.language : 'Plain Text';    return tag;});let unique = [...new Set(tags)]; const unique_tags = unique.map((tag) => {    return <Tag value={tag}/>;});The code starts by creating an array out of the files' JSON object, next it maps through the files array and returns the value of the language key (Javascript, C, etc.) and if its not undefined, returns plaintext. After that, it filters so there are only unique tags. Finally, it maps through the unique tags and returns a React component.As you can see, there are two maps and one filter. I feel like this could be done more efficiently.The JSON is coming from the GitHub Gist API.For example: https://api.github.com/gists/25c75fa76cf151568d12
ES6 Javascript (React) code that maps and filters JSON data
javascript;json;ecmascript 6;react.js
One thing to note about your code is that the array of files is looped over many times so depending on the size of this array, it could be slow.Here's the places where I see a loop:Line 1: Object.values(gist.files) loops over each file object property and returns it's valueLine 2: files.map(file) loops over each file value to return a stringLine 6: new Set(tags) loops over each value in the array to get unique valuesLine 6: [...set] loops over each value in the set to create a Shallow Clone of as an ArrayLine 7 unique.map loops over each value in the unique Array to return an array of JSX NodesNow the time complexity is only O(n) in your example code so it will scale but you can improve the speed by roughly 5x by doing a single loop instead of 5.Below is a single loop with time complexity of O(n).function getTagElements(gist) {  const tags = new Set();  const arr = [];  for (let file of gist.files) {      const tag = file.language ? file.language : 'Plain Text';      if (!tags.has(tag)) {          arr.push(<Tag value={tag}/>);          tags.add(tag);      }  }  return arr;}function Tag(props) {    // render your tag}<script src=https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react.min.js></script><script src=https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react-dom.min.js></script>Note that adding an item to a set is typically an O(1) operation (constant time operation).Attempting to use Array.indexOf is a O(n) operation and will not scale well with many values.