Skip to content

Instantly share code, notes, and snippets.

@angelyoung24
Created August 20, 2020 00:58
Show Gist options
  • Save angelyoung24/2f211f72999b55731288e8079ac07abb to your computer and use it in GitHub Desktop.
Save angelyoung24/2f211f72999b55731288e8079ac07abb to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/civugay
<!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">
// moveZeros([1, 2, 0, 1, 0, 0, 3, 6])
// [1, 2, 1, 3, 6, 0, 0, 0]
// I know, I know, it's not clean code!
// I wanted to use array prototype and I had no time to do the problem.
// At least I used const and not var
const moveZeros = [1, 2, 0, 1, 0, 0, 3, 6];
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
console.log(moveZeros);
</script>
<script id="jsbin-source-javascript" type="text/javascript">// moveZeros([1, 2, 0, 1, 0, 0, 3, 6])
// [1, 2, 1, 3, 6, 0, 0, 0]
// I know, I know, it's not clean code!
// I wanted to use array prototype and I had no time to do the problem.
// At least I used const and not var
const moveZeros = [1, 2, 0, 1, 0, 0, 3, 6];
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
console.log(moveZeros);
</script></body>
</html>
// moveZeros([1, 2, 0, 1, 0, 0, 3, 6])
// [1, 2, 1, 3, 6, 0, 0, 0]
// I know, I know, it's not clean code!
// I wanted to use array prototype and I had no time to do the problem.
// At least I used const and not var
const moveZeros = [1, 2, 0, 1, 0, 0, 3, 6];
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
moveZeros.push(moveZeros.splice(moveZeros.indexOf(0), 1)[0]);
console.log(moveZeros);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment