Created
October 1, 2020 18:28
-
-
Save forrest-akin/9e954e69632a0d7ecacc8f14f82303a2 to your computer and use it in GitHub Desktop.
This file contains 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 firstMissingPositive = | |
xs => { | |
for ( const x of xs ) | |
indexByValue( x , xs ) | |
let ndx = 0 | |
while ( xs[ ndx ] === ++ndx ) {} | |
return ndx | |
} | |
const indexByValue = | |
( x , xs ) => | |
xs[ x - 1 ] !== x | |
&& 0 < x | |
&& x <= xs.length | |
&& ( y = xs[ x - 1 ] | |
, xs[ x - 1 ] = x | |
, indexByValue( y , xs ) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment