Created
July 16, 2019 05:16
-
-
Save aire-con-gas/89276d825fe73b8fbc83b2a4cacd9038 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zuqipaj
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
"use strict"; | |
var vals = [6, 4, 2, 9, 7]; | |
function partition(arr, left, right) { | |
var x = arr[left]; | |
var j = left; | |
for (var i = left + 1; i < right; i++) { | |
if (arr[i] <= x) { | |
j = j + 1; | |
var _ref = [arr[i], arr[j]]; | |
arr[j] = _ref[0]; | |
arr[i] = _ref[1]; | |
} | |
} | |
var _ref2 = [arr[j], arr[left]]; | |
arr[left] = _ref2[0]; | |
arr[j] = _ref2[1]; | |
return j; | |
} | |
console.log(partition(vals, 0, vals.length)); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const vals = [6, 4, 2, 9, 7]; | |
function partition(arr, left, right) { | |
const x = arr[left]; | |
let j = left; | |
for(let i = left + 1; i < right; i++) { | |
if (arr[i] <= x) { | |
j = j + 1; | |
[arr[j], arr[i]] = [arr[i], arr[j]]; | |
} | |
} | |
[arr[left], arr[j]] = [arr[j], arr[left]]; | |
return j; | |
} | |
console.log(partition(vals, 0, vals.length));</script></body> | |
</html> |
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
"use strict"; | |
var vals = [6, 4, 2, 9, 7]; | |
function partition(arr, left, right) { | |
var x = arr[left]; | |
var j = left; | |
for (var i = left + 1; i < right; i++) { | |
if (arr[i] <= x) { | |
j = j + 1; | |
var _ref = [arr[i], arr[j]]; | |
arr[j] = _ref[0]; | |
arr[i] = _ref[1]; | |
} | |
} | |
var _ref2 = [arr[j], arr[left]]; | |
arr[left] = _ref2[0]; | |
arr[j] = _ref2[1]; | |
return j; | |
} | |
console.log(partition(vals, 0, vals.length)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment