Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Skew-symmetric Matrix by SaintDron
"use strict";
function symmetric(matrix) {
const size = matrix.length;
for (let i = 0; i < size; i++) {
for (let j = i; j < size; j++) {
if (matrix[i][j] !== -matrix[j][i])
return false;
}
}
return true;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(symmetric([
[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]))
// These "asserts" using only for self-checking and not necessary for auto-testing
assert.equal(symmetric([
[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]), true);
assert.equal(symmetric([
[0, 1, 2],
[-1, 1, 1],
[-2, -1, 0]]), false);
assert.equal(symmetric([
[0, 1, 2],
[-1, 0, 1],
[-3, -1, 0]]), false);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
June 25, 2018