<commit_before>import React from 'react';
import { leftNavItems } from '../LeftNav/LeftNavItems';

class PreviousAndNextLinks extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      prevLink: {},
      nextLink: {}
    }
  }
    componentDidMount(){
      let location;
      if (typeof window !== 'undefined') {
        location = window.location.pathname;
      }
      /* Using LeftNavItems.jsx, we filter through the nested arrays and return the active nav section the user is on */
    const activeDocLinks = [];
    /* Parent array */
    leftNavItems.forEach((leftNavItem) => {
      /* Loop over first submenu (subMenuItems1) */
      leftNavItem.subMenuItems1.map((subMenuItem1, index) => {
        /* Filter first submenu array */
        leftNavItem.subMenuItems1[index].url === location && activeDocLinks.push(leftNavItem.subMenuItems1)
        /* Filter second submenu array */
        subMenuItem1.subMenuItems2 && subMenuItem1.subMenuItems2.filter(subMenuItem2 => subMenuItem2.url === location && activeDocLinks.push(subMenuItem1.subMenuItems2))
      })
    })
    /* If the current location url equals the matching element index url, add the element to previous and next variables */
    let previous;
    let next;
    activeDocLinks.map(link => {
      for (let i = 0; i < link.length; i++) {
        if (link[i].url === location) {
          previous = link[i + -1]
          next = link[i + 1] && link[i + 1].slug ? undefined : link[i + 1]
        }
      }
    })
      this.setState({
        prevLink: previous,
        nextLink: next
      })
    }
  render() {
    const { nextLink, prevLink } = this.state;
    return (
      <div className="d-flex">
        {prevLink && (
          <div>
            <p className="font-weight-bold mb-0">Previous</p>
            <a href={prevLink.url}>{prevLink.name}</a>
          </div>
        )}
        {nextLink && (
          <div className={prevLink ? 'ml-auto' : ''}>
            <p className="font-weight-bold mb-0">Next</p>
            <a href={nextLink.url}>{nextLink.name}</a>
          </div>
        )}<commit_msg>Update previous algo<commit_after>import React from 'react';
import { leftNavItems } from '../LeftNav/LeftNavItems';

class PreviousAndNextLinks extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      prevLink: {},
      nextLink: {}
    }
  }
    componentDidMount(){
      let location;
      if (typeof window !== 'undefined') {
        location = window.location.pathname;
      }
      /* Using LeftNavItems.jsx, we filter through the nested arrays and return the active nav section the user is on */
    const activeDocLinks = [];
    /* Parent array */
    leftNavItems.forEach((leftNavItem) => {
      /* Loop over first submenu (subMenuItems1) */
      leftNavItem.subMenuItems1.map((subMenuItem1, index) => {
        /* Filter first submenu array */
        leftNavItem.subMenuItems1[index].url === location && activeDocLinks.push(leftNavItem.subMenuItems1)
        /* Filter second submenu array */
        subMenuItem1.subMenuItems2 && subMenuItem1.subMenuItems2.filter(subMenuItem2 => subMenuItem2.url === location && activeDocLinks.push(subMenuItem1.subMenuItems2))
      })
    })
    /* If the current location url equals the matching element index url, add the element to previous and next variables */
    let previous;
    let next;
    activeDocLinks.map(link => {
      for (let i = 0; i < link.length; i++) {
        if (link[i].url === location) {
          previous = link[i + -1] && link[i + -1].slug ? undefined : link[i + -1]
          next = link[i + 1] && link[i + 1].slug ? undefined : link[i + 1]
        }
      }
    })
      this.setState({
        prevLink: previous,
        nextLink: next
      })
    }
  render() {
    const { nextLink, prevLink } = this.state;
    return (
      <div className="d-flex">
        {prevLink && (
          <div>
            <p className="font-weight-bold mb-0">Previous</p>
            <a href={prevLink.url}>{prevLink.name}</a>
          </div>
        )}
        {nextLink && (
          <div className={prevLink ? 'ml-auto' : ''}>
            <p className="font-weight-bold mb-0">Next</p>
            <a href={nextLink.url}>{nextLink.name}</a>
          </div>
        )}
{'fraction_non_alphanumeric': 0.1376189371083778, 'fraction_numerical': 0.009747041076815966, 'mean_word_length': 2.285060975609756, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2266551', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1274, 'n_words': 303}