Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 99 additions & 17 deletions src/assets/data.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,103 @@
/**
* Displays and runs any or all of the tests.
*
* Get current date-time string:
* > new Date().toISOString()
*/
const data = [
//{ num: 2, name: "", method: "addTwoNumbers", url: "" },
{ num: 3, name: "Length of Longest Substring", method: "lengthOfLongestSubstring", site: "leetcode",
//--------- fbprep ----------
{ num: 1, name: "Rotational Cipher", method: "rotationalCipher", params: 2, site: "fbprep", categories: ["Starter Plan", "Strings"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=238827593802550&ppid=454615229006519&practice_plan=1" },
{ num: 2, name: "Contiguous Subarrays", method: "countSubarrays", site: "fbprep", categories: ["Starter Plan", "Arrays"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=226517205173943&ppid=454615229006519&practice_plan=1" },
{ num: 3, name: "Pair Sums", method: "numberOfWays", params: 2, site: "fbprep", categories: ["Starter Plan", "Hash Tables"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=840934449713537&ppid=454615229006519&practice_plan=1" },
{ num: 4, name: "Reverse to Make Equal", method: "areTheyEqual", params: 2, site: "fbprep", categories: ["Arrays"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=2869293499822992&ppid=454615229006519&practice_plan=0" },
{ num: 5, name: "Passing Yearbooks", method: "findSignatureCounts", site: "fbprep", categories: ["Arrays"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=146466059993201&ppid=454615229006519&practice_plan=0" },
{ num: 6, name: "Minimizing Permutations", method: "minOperations", site: "fbprep", categories: ["Graphs"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=292715105029046&ppid=454615229006519&practice_plan=0" },
{ num: 7, name: "Largest Triple Products", method: "findMaxProduct", site: "fbprep", categories: ["Heaps"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=510655302929581&c=1487359448291480&ppid=454615229006519&practice_plan=0" },
{ num: 8, name: "Slow Sums", method: "getTotalTime", site: "fbprep", categories: ["Greedy algorithms"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=836241573518034&c=1487359448291480&ppid=454615229006519&practice_plan=0" },
{ num: 9, name: "Element Swapping", method: "findMinArray", params: 2, site: "fbprep", categories: ["Greedy algorithms"],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=838749853303393&c=1487359448291480&ppid=454615229006519&practice_plan=0" },
{ num: 10, name: "Number of Visible Nodes", method: "visibleNodes", site: "fbprep", categories: [""],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=495004218121393&c=1487359448291480&ppid=454615229006519&practice_plan=0" },
{ num: 11, name: "Revenue Milestones", method: "getMilestoneDays", params: 2, site: "fbprep", categories: [""],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=192049171861831&c=1487359448291480&ppid=454615229006519&practice_plan=0" },
{ num: 12, name: "Balance Brackets", method: "isBalancedFb", site: "fbprep", categories: [""],
url: "https://www.facebookrecruiting.com/portal/coding_practice_question/?problem_id=211548593612944&c=1487359448291480&ppid=454615229006519&practice_plan=0" },
// { num: , name: "", method: "", site: "fbprep", categories: [""],
// url: "" },

//--------- hackerrank ----------
{ num: 1, name: "Balanced Brackets", method: "isBalanced", site: "hackerrank", difficulty: "Medium",
url: "https://www.hackerrank.com/challenges/balanced-brackets/problem" },
{ num: 2, name: "Tree: Height of a Binary Tree", method: "heightCode", site: "hackerrank", difficulty: "Easy",
url: "https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree/problem" },
{ num: 3, name: "Tree: Level Order Traversal", method: "levelOrderCode", site: "hackerrank", difficulty: "Easy",
url: "https://www.hackerrank.com/challenges/tree-level-order-traversal/problem" },
{ num: 4, name: "Contacts", method: "contacts", site: "hackerrank", difficulty: "Medium",
url: "https://www.hackerrank.com/challenges/contacts/problem" },
{ num: 5, name: "Find the Running Median", method: "runningMedian", site: "hackerrank", difficulty: "Hard",
url: "https://www.hackerrank.com/challenges/find-the-running-median", incomplete: true },
{ num: 6, name: "Swap Nodes [Algo]", method: "swapNodes", site: "hackerrank", difficulty: "Easy",
url: "https://www.hackerrank.com/challenges/swap-nodes-algo/problem" },
// { num: , name: "", method: "", site: "hackerrank", difficulty: "Easy",
// url: "" },
// https://www.hackerrank.com/challenges/find-the-running-median
// https://www.hackerrank.com/challenges/swap-nodes-algo

//--------- leetcode ----------
{ num: 2, name: "Add Two Numbers", method: "addTwoNumbers2", params: 2, site: "leetcode", difficulty: "Medium", tags: ['fb'],
url: "https://leetcode.com/problems/add-two-numbers/" },
{ num: 3, name: "Length of Longest Substring", method: "lengthOfLongestSubstring", site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/longest-substring-without-repeating-characters" },
{ num: 4, name: "Find Median Sorted Arrays", method: "findMedianSortedArrays", params: 2, site: "leetcode",
{ num: 4, name: "Find Median Sorted Arrays", method: "findMedianSortedArrays", params: 2, site: "leetcode", difficulty: "Hard",
url: "https://leetcode.com/problems/median-of-two-sorted-arrays" },
{ num: 5, name: "Longest Palindromic Substring", method: "longestPalindrome", site: "leetcode",
{ num: 5, name: "Longest Palindromic Substring", method: "longestPalindrome", site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/longest-palindromic-substring" },
{ num: 6, name: "ZigZag Conversion", method: "zigZagConvert", params: 2, site: "leetcode",
{ num: 6, name: "ZigZag Conversion", method: "zigZagConvert", params: 2, site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/zigzag-conversion" },
{ num: 8, name: "String to Integer (atoi)", method: "myAtoi", site: "leetcode",
{ num: 8, name: "String to Integer (atoi)", method: "myAtoi", site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/string-to-integer-atoi/submissions/" },
{ num: 993, name: "Number of Recent Calls", method: "numberOfRecentCalls", site: "leetcode",
{ num: 43, name: "Multiply Strings", method: "multiply", params: 2, site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/multiply-strings/" },
{ num: 140, name: "Word Break II", method: "wordBreak", params: 2, site: "leetcode", difficulty: "Hard",
url: "https://leetcode.com/problems/word-break-ii/" },
{ num: 187, name: "Repeated DNA Sequences", method: "findRepeatedDnaSequences", site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/repeated-dna-sequences" },
{ num: 199, name: "Binary Tree Right Side View", method: "rightSideView", site: "leetcode", difficulty: "Medium", tags: ['fb'],
url: "https://leetcode.com/problems/binary-tree-right-side-view/" },
{ num: 219, name: "Contains Duplicate II", method: "containsNearbyDuplicate", params: 2, site: "leetcode", difficulty: "Easy", tags: ['fb'],
url: "https://leetcode.com/problems/contains-duplicate-ii/" },
{ num: 227, name: "Basic Calculator II", method: "calculate", site: "leetcode", difficulty: "Medium", tags: ['fb'],
url: "https://leetcode.com/problems/basic-calculator-ii/" },
{ num: 415, name: "Add Strings", method: "addStrings", params: 2, site: "leetcode", difficulty: "Easy",
url: "https://leetcode.com/problems/add-strings/" },
{ num: 680, name: "Valid Palindrome II", method: "validPalindrome", site: "leetcode", difficulty: "Easy", tags: ['fb'],
url: "https://leetcode.com/problems/valid-palindrome-ii/", },
{ num: 993, name: "Number of Recent Calls", method: "numberOfRecentCalls", site: "leetcode", difficulty: "Easy",
url: "https://leetcode.com/problems/number-of-recent-calls/" },
{ num: 1288, name: "Remove Covered Intervals", method: "removeCoveredIntervals", site: "leetcode",
{ num: 1288, name: "Remove Covered Intervals", method: "removeCoveredIntervals", site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/remove-covered-intervals/" },
{ num: 187, name: "Repeated DNA Sequences", method: "findRepeatedDnaSequences", site: "leetcode",
url: "https://leetcode.com/problems/repeated-dna-sequences" },
{ num: 1608, name: "Special Array With X Elements Greater Than or Equal X", method: "specialArray", site: "leetcode",
{ num: 1343, name: "Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold", method: "numOfSubarrays", params: 3, site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/" },
{ num: 1608, name: "Special Array With X Elements Greater Than or Equal X", method: "specialArray", site: "leetcode", difficulty: "Easy",
url: "https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x" },
{ num: 1609, name: "Even Odd Tree", method: "isEvenOddTree", site: "leetcode",
url: "https://leetcode.com/problems/even-odd-tree/", incomplete: true },

//--------- Project Euler ----------
{ num: 1, name: "Multiples of 3 and 5", method: "sumOfMultiples3and5", params: 2, site: "projecteuler",
url: "https://projecteuler.net/problem=1" },
{ num: 1609, name: "Even Odd Tree", method: "isEvenOddTree", site: "leetcode", difficulty: "Medium",
url: "https://leetcode.com/problems/even-odd-tree/", dtCompleted: "2021-11-09T12:18:36.208Z" },
{ num: 9001, name: "Minimum Swaps to Group All 1's Together", method: "minSwaps", site: "leetcode", difficulty: "Medium", tags: ['amazon'],
url: "https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together/" },//number is unknown
{ num: 1359, name: "Count All Valid Pickup and Delivery Options", method: "countOrders", site: "leetcode", difficulty: "Hard", tags: ['fb'],
url: "https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options/" },
{ num: 210, name: "Course Schedule II", method: "findOrder", params: 2, site: "leetcode", difficulty: "Medium", tags: ['fb'],
url: "https://leetcode.com/problems/course-schedule-ii/", incomplete: true },
// { num: , name: "", method: "", site: "leetcode", difficulty: "Easy", tags: ['fb'],
// url: "" },

//--------- code.golf ----------
{ num: 1, name: "12 Days of Christmas", method: "print12DaysOfChristmas", site: "code.golf",
Expand All @@ -53,4 +124,15 @@ const data = [
url: "https://code.golf/vampire-numbers#javascript" },
{ num: 13, name: "Rock Paper Scissors Spock Lizard", method: "rpssl", site: "code.golf",
url: "https://code.golf/rock-paper-scissors-spock-lizard#javascript" },
{ num: 14, name: "Look and Say", method: "lookAndSay", site: "code.golf",
url: "https://code.golf/look-and-say#javascript" },
{ num: 15, name: "Pascal’s Triangle", method: "pascalsTriangle", site: "code.golf",
url: "https://code.golf/pascals-triangle#javascript" },
{ num: 16, name: "Poker", method: "poker", site: "code.golf",
url: "https://code.golf/poker#javascript", incomplete: true },

//--------- Project Euler ----------
{ num: 1, name: "Multiples of 3 and 5", method: "sumOfMultiples3and5", params: 2, site: "projecteuler",
url: "https://projecteuler.net/problem=1" },

];
46 changes: 46 additions & 0 deletions src/assets/fbprep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//-------------------------------------
// Code found in all fbprep tests
//-------------------------------------

// These are the tests we use to determine if the solution is correct.
// You can add your own at the bottom.
const printintegerArray = arr => `[${arr.join(", ")}]`;

const printInteger = n => `[${n}]`;

const printString = str => `["${str}"]`;

const printVal = val => {
if (Number.isInteger(0)) return printInteger(val);
else if (Array.isArray(val) && val.length > 0) {
if (Number.isInteger(val[0])) return printintegerArray(val);
else if (typeof val[0] === 'string') return `["${val.join('", "')}"]`
}
else if (typeof val === 'string') return printString(val);
};

var test_case_number = 1;

function check(expected, output) {
var expected_size = expected.length;
var output_size = output.length;
var result = true;

if (expected_size != output_size) result = false;

for (var i = 0; i < Math.min(expected_size, output_size); i++) {
result &= (output[i] == expected[i]);
}

var rightTick = "\u2713";
var wrongTick = "\u2717";
if (result) {
console.log(rightTick + ' Test #' + test_case_number);
}
else {
console.log(
`${wrongTick} Test #${test_case_number}: Expected ${printVal(expected)} Your output: ${printVal(output)}`
);
}
test_case_number++;
}
36 changes: 36 additions & 0 deletions src/code.golf/0014-lookAndSay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const lookAndSayCode = print => {

n="1";print(n);for(i=0;i<19;i++){t=0;arr=""
for(j=0;j<n.length;j++){t++;c=n.charAt(j);if(c!==n.charAt(j+1)){arr+=t+""+c;t=0}}print(n=arr)}

};

const lookAndSay = () => {
let output = [];
lookAndSayCode(str => output.push(str));
return output.join("\n");
};

const lookAndSayTests = [
['',`1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221
3113112221232112111312211312113211
1321132132111213122112311311222113111221131221
11131221131211131231121113112221121321132132211331222113112211
311311222113111231131112132112311321322112111312211312111322212311322113212221
132113213221133112132113311211131221121321131211132221123113112221131112311332111213211322211312113211
11131221131211132221232112111312212321123113112221121113122113111231133221121321132132211331121321231231121113122113322113111221131221
31131122211311123113321112131221123113112211121312211213211321322112311311222113311213212322211211131221131211132221232112111312111213111213211231131122212322211331222113112211
1321132132211331121321231231121113112221121321132122311211131122211211131221131211132221121321132132212321121113121112133221123113112221131112311332111213122112311311123112111331121113122112132113213211121332212311322113212221
11131221131211132221232112111312111213111213211231132132211211131221131211221321123113213221123113112221131112311332211211131221131211132211121312211231131112311211232221121321132132211331121321231231121113112221121321133112132112312321123113112221121113122113121113123112112322111213211322211312113211`
]
];
48 changes: 48 additions & 0 deletions src/code.golf/0015-pascalsTriangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const pascalsTriangleCode = print => {
print(1);
arr=[1];
for(i=0;i<19;i++){
l=arr.length;
nextArr=[];
nextArr.push(arr[0]);
for(j=0;j<l-1;j++)
nextArr.push(arr[j] + arr[j+1]);
nextArr.push(arr[l-1]);
print(nextArr.join(" "));
arr = nextArr;
}
/*
Minified
print(1);a=[1];for(i=0;i<19;i++){l=a.length;n=[];n.push(a[0]);for(j=0;j<l-1;j++)n.push(a[j]+a[j+1]);n.push(a[l-1]);print(n.join(" "));a=n;}
*/
};

const pascalsTriangle = () => {
let output = [];
pascalsTriangleCode(str => output.push(str));
return output.join("\n");
};

const pascalsTriangleTests = [
['',`1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
1 11 55 165 330 462 462 330 165 55 11 1
1 12 66 220 495 792 924 792 495 220 66 12 1
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1
1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1
1 16 120 560 1820 4368 8008 11440 12870 11440 8008 4368 1820 560 120 16 1
1 17 136 680 2380 6188 12376 19448 24310 24310 19448 12376 6188 2380 680 136 17 1
1 18 153 816 3060 8568 18564 31824 43758 48620 43758 31824 18564 8568 3060 816 153 18 1
1 19 171 969 3876 11628 27132 50388 75582 92378 92378 75582 50388 27132 11628 3876 969 171 19 1`
]
];
82 changes: 82 additions & 0 deletions src/code.golf/0016-poker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

//Spades 0/Hearts 1/Diamonds 2/Clubs 3
deck="🂡🂮🂭🂫🂪🂩🂨🂧🂦🂥🂤🂣🂢🂱🂾🂽🂻🂺🂹🂸🂷🂶🂵🂴🂳🂲🃁🃎🃍🃋🃊🃉🃈🃇🃆🃅🃄🃃🃂🃑🃞🃝🃛🃚🃙🃘🃗🃖🃕🃔🃓🃒".split(/.*?/u);

const pokerCode = (print, arguments) => {
print(arguments.map(hand => {
handArr = hand.split(/.*?/u).map(card => {
cardIndex = deck.indexOf(card);
return { num: cardIndex % 13, suit: Math.floor(cardIndex / 13) };
});
handArr.sort((a, b) => a.num - b.num);
let isStraight = isFlush = isFour = isFull = isThree = isTwoPair = isPair = true;
let prevCard, map = {};
handArr.map(card => {
const {num, suit} = card;
if (prevCard && num + 1 !== prevCard.num) isStraight = false;
if (prevCard && suit !== prevCard.suit) isFlush = false;
index = card.suit+""+num;
if (!map[num]) map[num] = 0;
map[num]++;
prevCard = card;
});
Object.keys(map).forEach(key => {
if (map[key] === 4) {
isFull = false;
isThree = false;
isTwoPair = false;
isPair = false;
}
else if (map[key] === 3) isThree = false;
})
if (isStraight && isFlush) if (handArr[4].num === 12) return "Royal Flush"; else return "Straight Flush";
return "High Card";
}).join("\n"));
};

const poker = arguments => {
let output = [];
pokerCode(str => output.push(str), arguments);
return output.join("\n");
};

const pokerTests = [
["🂢🃆🃑🂾🃛 🂪🂤🂥🂻🃒 🃃🂳🃓🃉🂣 🃓🃛🃘🃝🃔 🃗🃞🃖🃓🃘 🃚🃞🃛🃑🃝 🂡🂭🂫🂪🂮 🂱🂮🂲🂳🂴 🂹🂸🂷🂺🂶 🃗🃚🂱🂪🂸 🂥🂤🂣🂢🂡 🃎🃊🃁🃋🃍 🂪🂵🃑🂻🂱 🃃🂢🂪🃕🂴 🃍🃒🃕🃓🃑 🂻🂺🂾🂽🂹 🂵🂹🂾🂺🂱 🃞🃑🂱🂮🂾 🃈🃑🂽🂭🂨 🃃🃑🃄🃂🃅 🂲🂳🂱🂭🂮 🃄🂤🂹🂲🃔 🂤🃂🂩🂲🂢 🃙🃑🃃🂩🃁 🃝🂽🃍🂭🃞 🂱🂾🂺🂻🂽 🃎🂨🂮🂾🃞 🃇🂧🂳🂷🂣 🂧🃄🂷🂤🂴 🃄🃂🂾🃃🃁 🂨🃇🃉🂪🃖 🂺🂽🃞🂡🃛 🃃🃇🂢🃒🃂 🃒🃔🃎🃓🃑 🃎🂦🃚🂲🂶 🃂🂨🃅🂢🂥 🃁🂾🃃🃈🃅".split(" "),
`High Card
High Card
Four of a Kind
Flush
Flush
Royal Flush
Royal Flush
High Card
Straight Flush
Pair
Straight Flush
Royal Flush
Pair
High Card
High Card
Straight Flush
Flush
Full House
Two Pair
Straight
High Card
Three of a Kind
Three of a Kind
Two Pair
Four of a Kind
Royal Flush
Four of a Kind
Full House
Full House
High Card
Straight
Straight
Three of a Kind
High Card
Pair
Two Pair
High Card`]
];
Loading