Last active
May 9, 2019 03:10
-
-
Save JimRottinger/1383965a17b2caec51e48a80a5e9983e to your computer and use it in GitHub Desktop.
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 checkLoopInvariant = (newArray, originalArray, index) => { | |
newArray = newArray.slice(0, index) | |
originalArray = originalArray.sort((a,b) => a > b ? 1 : - 1).slice(0,index) | |
if (index === 0) return true //no elements sorted yet | |
for (let i = 0; i < newArray.length; i++) { | |
if (!originalArray.includes(newArray[i])) { | |
console.warn(`Error! ${newArray[i]} not one of the ${index} smallest elements`) | |
} | |
if (i < newArray.length - 1 && newArray[i] > newArray[i+1]) { | |
console.warn(`Error! New Array is not properly sorted`) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment