Skip to content

Instantly share code, notes, and snippets.

@almost
Last active August 21, 2017 01:00
Show Gist options
  • Save almost/00eb76ae24a533384b18c5b2f77cea9e to your computer and use it in GitHub Desktop.
Save almost/00eb76ae24a533384b18c5b2f77cea9e to your computer and use it in GitHub Desktop.
Problems from last night's Code Golf at Async.JS

Yes? No?

Make a function (named 'play') that takes a boolean (true or false) and returns the string 'y' (for true) or 'n' (for false)

To the power of JavaScript

Make a function that takes a number between 1 and 30 and returns 2 raised to the power of that number. (you can use ES2015 but nothing beyond that)

The Nth Letter

Make a function that takes a number n between 1 and 26 and returns the nth letter of the alphabet. For example play(1) would return 'a' and play(26) would return 'z

How about a nice game of chess?

Make a function that produces an ASCII chessboard using # characters for the black squares and spaces for the white. The input of the function is a number giving the size of each square in characters. For example for an input of 2 the output would be "## ## ## ## \n## ## ## ## \n ## ## ## ##\n ## ## ## ##\n## ## ## ## \n## ## ## ## \n ## ## ## ##\n ## ## ## ##\n## ## ## ## \n## ## ## ## \n ## ## ## ##\n ## ## ## ##\n## ## ## ## \n## ## ## ## \n ## ## ## ##\n ## ## ## ##\n"

(note the trailing newline).

##  ##  ##  ##  
##  ##  ##  ##  
  ##  ##  ##  ##
  ##  ##  ##  ##
##  ##  ##  ##  
##  ##  ##  ##  
  ##  ##  ##  ##
  ##  ##  ##  ##
##  ##  ##  ##  
##  ##  ##  ##  
  ##  ##  ##  ##
  ##  ##  ##  ##
##  ##  ##  ##  
##  ##  ##  ##  
  ##  ##  ##  ##
  ##  ##  ##  ##

JavaScript Assemble!

Make a function that receives a string containing commands (one per line) and applies them to a number (that starts as 0). The commands are add, subtract and mulltiply. So if you get the string "add 10\nsubtract 2\nmultiply 2" the result would be 16.

What's a Regional Indicator Symbol?

Make a function that takes an array of two letter ISO country codes (eg ["GB", "US"]) and produces a unicode/emoji flag (eg ["๐Ÿ‡ฌ๐Ÿ‡ง","๐Ÿ‡บ๐Ÿ‡ธ"]). Only needs to support the ten countries in the core set: CN, DE, ES, FR, GB, IT, JP, KR, RU, US (๐Ÿ‡ฎ๐Ÿ‡น, ๐Ÿ‡จ๐Ÿ‡ณ, ๐Ÿ‡บ๐Ÿ‡ธ, ๐Ÿ‡ช๐Ÿ‡ธ, ๐Ÿ‡ฉ๐Ÿ‡ช, ๐Ÿ‡ฏ๐Ÿ‡ต, ๐Ÿ‡ฐ๐Ÿ‡ท, ๐Ÿ‡ท๐Ÿ‡บ, ๐Ÿ‡ซ๐Ÿ‡ท, ๐Ÿ‡ฌ๐Ÿ‡ง)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment