Created
November 18, 2019 22:36
-
-
Save martea/e63e68893eb2a146462088d969e316c3 to your computer and use it in GitHub Desktop.
assert js
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
function Assert() { | |
} | |
Assert.prototype.equal = function (cb, result, title) { | |
var correct = cb == result; | |
console.log(title + ", ", correct, !correct ? `, expected ${result} but was ${cb}` : ""); | |
} | |
var assert = new Assert(); | |
function countNeighbours(arrCollection, row, col) { | |
var matches = 0; | |
console.log(arrCollection,row,col) | |
console.log(arrCollection[col][row]); | |
console.log(arrCollection[0][col][row]); | |
var itterate =2 ; | |
for (let c = 0; c < itterate.length; c++) { | |
for (let r = 0; r < itterate.length; r++) { | |
const element = array[r]; | |
} | |
} | |
// for (let i = 0; i < arrCollection.length; i++) { | |
// const arr = arrCollection[i]; | |
// // console.log(arr); | |
// var currentColumn = i; | |
// for (let j = 0; j < arr.length; j++) { | |
// const currentRow = j; | |
// const element = arr[j]; | |
// const lowRowIndex = row - 1 <= 0 ? 0 : row - 1; | |
// const highRowIndex = row + 1 >= arr.length ? arr.length : row + 1; | |
// const lowColIndex = col - 1 <= 0 ? 0 : col - 1; | |
// const highColIndex = col + 1 >= arrCollection.length ? arrCollection.length : col + 1; | |
// console.log(lowRowIndex,highRowIndex,lowColIndex,highColIndex) | |
// if (currentRow >= lowRowIndex && currentRow <= highRowIndex && currentColumn >= lowColIndex && currentColumn <= highColIndex) { | |
// if (element == 1) { | |
// matches++; | |
// } | |
// } | |
// } | |
// } | |
console.log(matches); | |
return matches; | |
} | |
assert.equal(countNeighbours([[1, 0, 0, 1, 0], | |
[0, 1, 0, 0, 0], | |
[0, 0, 1, 0, 1], | |
[1, 0, 0, 0, 0], | |
[0, 0, 1, 0, 0]], 1, 2), 3, "1st example"); | |
assert.equal(countNeighbours([[1, 0, 0, 1, 0], | |
[0, 1, 0, 0, 0], | |
[0, 0, 1, 0, 1], | |
[1, 0, 0, 0, 0], | |
[0, 0, 1, 0, 0]], 0, 0), 1, "2nd example"); | |
assert.equal(countNeighbours([[1, 1, 1], | |
[1, 1, 1], | |
[1, 1, 1]], 0, 2), 3, "Dense corner"); | |
assert.equal(countNeighbours([[0, 0, 0], | |
[0, 1, 0], | |
[0, 0, 0]], 1, 1), 0, "Single"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment