made with esnextbin
Created
November 1, 2016 23:51
-
-
Save amilajack/7fff74c7cf68deaff193a6c87180745e 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
// Validate if a board is invald | |
import { expect } from 'chai' | |
const some = [ | |
[0,0], [1,0], [2,0], | |
[0,1], [1,1], [2,1], | |
[0,2], [1,2], [2,2] | |
] | |
const foo = [ | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
[1, 4, 4, 2, 5, 5, 6, 7, 7], | |
] | |
console.clear() | |
function flatten(array) { | |
return array.reduce((prev, next) => [...prev, ...next], []) | |
} | |
function dupeRight(array) { | |
return array.map(each => [each[0] + 3, each[1]]) | |
} | |
function dupeBottom(array) { | |
return array.map(each => [each[0], each[1] + 3]) | |
} | |
/** | |
* @complexity Time Compexity: O(n^2) | |
* where n is the number of rows of the board | |
* @param {number} | |
*/ | |
function dupe(rowCount = 3) { | |
const items = [] | |
items.push(some) | |
for (let start = 0; start < rowCount; start++) { | |
for (let inner = 0; inner < rowCount - 1; inner++) { | |
items.push(dupeRight(items[items.length - 1])) | |
} | |
if (start !== 0) { | |
items.push(dupeBottom(items[items.length - 3])) | |
} | |
} | |
return items; | |
} | |
const moo = dupe() | |
console.log(moo) | |
const loo = new Set(); | |
moo[0].forEach(e => { | |
console.log('has', loo.has(e.toString())) | |
// loo.add(e.toString()) | |
// console.log() | |
}) |
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", | |
"dependencies": { | |
"chai": "3.5.0", | |
"babel-runtime": "6.18.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'; | |
var _set = require('babel-runtime/core-js/set'); | |
var _set2 = _interopRequireDefault(_set); | |
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | |
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | |
var _chai = require('chai'); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var some = [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2]]; // Validate if a board is invald | |
var foo = [[1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7], [1, 4, 4, 2, 5, 5, 6, 7, 7]]; | |
console.clear(); | |
function flatten(array) { | |
return array.reduce(function (prev, next) { | |
return [].concat((0, _toConsumableArray3.default)(prev), (0, _toConsumableArray3.default)(next)); | |
}, []); | |
} | |
function dupeRight(array) { | |
return array.map(function (each) { | |
return [each[0] + 3, each[1]]; | |
}); | |
} | |
function dupeBottom(array) { | |
return array.map(function (each) { | |
return [each[0], each[1] + 3]; | |
}); | |
} | |
/** | |
* @complexity Time Compexity: O(n^2) | |
* where n is the number of rows of the board | |
* @param {number} | |
*/ | |
function dupe() { | |
var rowCount = arguments.length <= 0 || arguments[0] === undefined ? 3 : arguments[0]; | |
var items = []; | |
items.push(some); | |
for (var start = 0; start < rowCount; start++) { | |
for (var inner = 0; inner < rowCount - 1; inner++) { | |
items.push(dupeRight(items[items.length - 1])); | |
} | |
if (start !== 0) { | |
items.push(dupeBottom(items[items.length - 3])); | |
} | |
} | |
return items; | |
} | |
var moo = dupe(); | |
console.log(moo); | |
var loo = new _set2.default(); | |
moo[0].forEach(function (e) { | |
console.log('has', loo.has(e.toString())); | |
// loo.add(e.toString()) | |
// console.log() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment