Skip to content

Commit

Permalink
adding more comparison screenshots and and an additional test for foi…
Browse files Browse the repository at this point in the history
…-toy
  • Loading branch information
getify committed Dec 19, 2022
1 parent d60cebe commit a46d58e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,22 @@ The following (incomplete) is a **Foi** cheatsheet: a list of comparisons betwee

## Comparison Examples

Here are some screenshots showing typical JS code (on top, in each image) to the equivalent **Foi** code (on bottom, in each image).
Here are some screenshots showing typical JS code (on top or left, in each image) to the equivalent **Foi** code (on bottom or right, in each image).

<table>
<tr>
<td valign="top"><a href="foi-js-comparison-1.png"><img src="foi-js-comparison-1.png" width=300 alt="Comparison: chunking an array"></a></td>
<td rowspan="2" valign="top"><a href="foi-js-comparison-3.png"><img src="foi-js-comparison-3.png" width=300 alt="Comparison: async..await fetch + rendering html"></a></td>
<td><a href="foi-js-comparison-1.png"><img src="foi-js-comparison-1.png" width=300 alt="Comparison: chunking an array"></a></td>
<td rowspan="2">
<a href="foi-js-comparison-3.png"><img src="foi-js-comparison-3.png" width=300 alt="Comparison: async..await fetch + rendering html"></a><br><br><a href="foi-js-comparison-2.png"><img src="foi-js-comparison-2.png" width=300 alt="Comparison: memoized fibonacci number computation"></a></td>
</tr>
<tr>
<td><a href="foi-js-comparison-2.png"><img src="foi-js-comparison-2.png" width=300 alt="Comparison: memoized fibonacci number computation"></a></td>
<td><a href="foi-js-comparison-4.png"><img src="foi-js-comparison-4.png" width=300 alt="Comparison: converting string of binary digits into base-10 number"></a></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="2"><a href="foi-js-comparison-5.png"><img src="foi-js-comparison-5.png" width=600 alt="Comparison: iterative BFS algorithm, finding size of largest region in matrix"></a></td>
</tr>
</table>

Expand Down
Binary file added foi-js-comparison-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added foi-js-comparison-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions foi-toy/test/test-6.foi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defn binaryToDecimalConverter(binaryDigits) {
def < :decimal >: (| ~fold
binaryDigits,
< decimal: 0, idx: 0, >,
(< :decimal, :idx >, digit) {
def power: size(binaryDigits) - idx - 1;
decimal := decimal + (digit * pow(2,power));
< :decimal, idx: |+ idx,1| >;
}
|);
^decimal;
};

binaryToDecimalConverter("111110011101100"); // 31980

0 comments on commit a46d58e

Please sign in to comment.