Skip to content

Instantly share code, notes, and snippets.

View evolutionxbox's full-sized avatar
👀
Trying my hardest

Jonathan Cousins evolutionxbox

👀
Trying my hardest
View GitHub Profile
@evolutionxbox
evolutionxbox / CanMakePalindrome.js
Last active April 6, 2016 15:18
Given a string `s`, determine whether or not it is possible to rearrange the letters in the string to make a palindrome. (Post manual "uglify")
CanMakePalindrome = (s, b, o, t) => {
t = s.length % 2;
o = [...s].filter(l => {
b = s.split(l);
s = b.join``;
return (b.length - 1)%2;
});
return t ? (o.length === 1) : (o.length === 0);
}
@evolutionxbox
evolutionxbox / TicTacToe.js
Last active April 6, 2016 13:35
You are given a 3 × 3 Tic-tac-toe board stored as a two-dimensional array. Find out the winner of the game, or return ' ' if there is no winner.
TicTacToe = (board) => {
let winbits = [7,56,73,84,146,273,292,448];
board = Array.prototype.concat.apply([], board);
query = player => {
num = 0;
board.forEach((cell, i) => {
var i = (board.length-i)-1;
num += (cell === player)<<i;
});
function ClosedBracketWord(w='w') {
return !w[19] && w.split('').every((l, i) => 122-(l.charCodeAt()-97) === w.charCodeAt(w.length-1-i));
}
ClosedBracketWord('abiryz'); // true
ClosedBracketWord('abixyz'); // false
ClosedBracketWord('ABCXYZ'); // false
ClosedBracketWord(''); // true
@evolutionxbox
evolutionxbox / es2015-class-compose.js
Last active May 3, 2016 10:07
Compositional Inheritance using ES2015 classes
class Openable {
constructor(isOpen = false) {
this._isOpen = isOpen;
}
get isOpen() {
return this._isOpen + ' is stupid.';
}