Implemented pancake sorter algorithm in Javascript