made with esnextbin
Created
June 15, 2017 23:11
-
-
Save amilajack/18f45ce0e0dea8291f9e159a0799ae78 to your computer and use it in GitHub Desktop.
esnextbin sketch
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</body> | |
</html> |
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
// write ES2015 code and import modules from npm | |
// and then press "Execute" to run your program | |
const stack = [4, 3, 13, 22, 2, 6, 8] | |
const tmp = [] | |
while (stack.length > 0) { | |
foo(stack.pop()) | |
} | |
function foo(item1) { | |
console.log(tmp) | |
if (tmp.length === 0) { | |
tmp.push(item1) | |
return | |
} | |
const item2 = tmp.pop() | |
if (tmp.length === 0) { | |
if (item1 <= item2) { | |
tmp.push(item2) | |
tmp.push(item1) | |
} else { | |
tmp.push(item1) | |
tmp.push(item2) | |
} | |
return; | |
} | |
const item3 = tmp.pop() | |
if ( | |
item1 >= item3 && | |
item1 <= item2 | |
) { | |
tmp.push(item3) | |
tmp.push(item1) | |
tmp.push(item2) | |
} else { | |
foo(item1) | |
tmp.push(item3) | |
tmp.push(item2) | |
} | |
} | |
// console.clear() | |
console.log(tmp) |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0" | |
} |
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
"use strict"; | |
// write ES2015 code and import modules from npm | |
// and then press "Execute" to run your program | |
var stack = [4, 3, 13, 22, 2, 6, 8]; | |
var tmp = []; | |
while (stack.length > 0) { | |
foo(stack.pop()); | |
} | |
function foo(item1) { | |
console.log(tmp); | |
if (tmp.length === 0) { | |
tmp.push(item1); | |
return; | |
} | |
var item2 = tmp.pop(); | |
if (tmp.length === 0) { | |
if (item1 <= item2) { | |
tmp.push(item2); | |
tmp.push(item1); | |
} else { | |
tmp.push(item1); | |
tmp.push(item2); | |
} | |
return; | |
} | |
var item3 = tmp.pop(); | |
if (item1 >= item3 && item1 <= item2) { | |
tmp.push(item3); | |
tmp.push(item1); | |
tmp.push(item2); | |
} else { | |
foo(item1); | |
tmp.push(item3); | |
tmp.push(item2); | |
} | |
} | |
// console.clear() | |
console.log(tmp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment