Last active
          January 2, 2023 10:10 
        
      - 
      
- 
        Save ChrisDobby/60f4cbbb3600ab5803618673f05332ec to your computer and use it in GitHub Desktop. 
    Given an array of integers arr and an integer n, return a subarray of arr of length n where the sum is the largest. Make sure you maintain the order of the original array
  
        
  
    
      This file contains hidden or 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 maxSubArray = (arr: number[], len: number) => | |
| arr.length < len | |
| ? [] | |
| : arr | |
| .map((_, index, a) => a.slice(index, index + len)) | |
| .filter(a => a.length === len) | |
| .sort((arr1, arr2) => Math.max(...arr2) - Math.max(...arr1))[0] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment