Last active
May 7, 2019 01:11
-
-
Save JimRottinger/77a7a929c9db23525a1a9c2b1b28815e 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 = (newArr, originalArr, index) => { | |
//need to slice at least 1 element out | |
if (index < 1) index = 1 | |
newArr = newArr.slice(0,index) | |
originalArr = originalArr.slice(0, index) | |
for (let i=0; i < newArr.length; i++) { | |
//check that the original array contains the value | |
if (!originalArr.includes(newArr[i])) { | |
console.error(`Failed! Original array does not include ${newArr[i]}`) | |
} | |
//check that the new array is in sorted order | |
if (i < newArr.length - 1 && newArr[i] > newArr[i+1]) { | |
console.error(`Failed! ${newArr[i]} is not less than ${newArr[i+1]}`) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment