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 filterListBySearch<T>( | |
list: T[], | |
props: Array<keyof T>, | |
searchText: string | |
) { | |
const regex = new RegExp(searchText, 'i') | |
return list.filter(it => props.some(prop => regex.test(`${it[prop]}`))) | |
} |
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
const formatSeconds = (seconds: number): string => { | |
const values = [24 * 60 * 60, 60 * 60, 60, 1] | |
const units = [ | |
['day', 'days'], | |
['hour', 'hours'], | |
['minute', 'minutes'], | |
['second', 'seconds'] | |
] | |
const parts = [] |
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 areBracketsBalanced(s) { | |
const opening = ['{', '[', '('] | |
const closing = ['}', ']', ')'] | |
const stack = [] | |
const closingFor = { | |
'{': '}', | |
'[': ']', | |
'(': ')', | |
} |
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 max(x: number, y: number): number { | |
return x > y ? x : y; | |
} | |
function min(x: number, y: number): number { | |
return x < y ? x : y; | |
} | |
function sum(list: number[]): number { | |
if (len(list) === 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
import 'package:flutter/material.dart'; | |
import 'package:flutter_stateless_chessboard/flutter_stateless_chessboard.dart'; | |
import 'utils.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} |
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
import 'package:flutter/material.dart'; | |
import 'home_page.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. |
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
import 'package:flutter/material.dart'; | |
import 'package:flutter_stateless_chessboard/flutter_stateless_chessboard.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
String _fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'; |
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
import 'package:chess/chess.dart' as ch; | |
String makeMove(String fen, dynamic move) { | |
final chess = ch.Chess.fromFEN(fen); | |
if (chess.move(move)) { | |
return chess.fen; | |
} | |
return null; |
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
describe("makeMove", () => { | |
test("should return fen and full move", () => { | |
expect( | |
makeMove( | |
"rnbqkbnr/pppp1ppp/8/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2", | |
"Bc5" | |
) | |
).toEqual({ | |
fen: "rnbqk1nr/pppp1ppp/8/2b1p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3", | |
fullMove: { |
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
const { getSideToPlayFromFen } = require("./utils"); | |
describe("getSideToPlayFromFen", () => { | |
test("should return white", () => { | |
expect( | |
getSideToPlayFromFen( | |
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" | |
) | |
).toBe("w"); | |
}); |
NewerOlder