Skip to content

Instantly share code, notes, and snippets.

@cassidoo
Last active December 11, 2021 19:05
Show Gist options
  • Save cassidoo/6101ef0657665683b787aab5ae9465f4 to your computer and use it in GitHub Desktop.
Save cassidoo/6101ef0657665683b787aab5ae9465f4 to your computer and use it in GitHub Desktop.
A gist of all of the functions that Copilot wrote for me
/**
As seen on twitch.tv/cassidoo
*/
// A function that validates an email address
function validateEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
// A function that validates if a string begins with the letter 'x' and is 4 characters long
function validateX(str) {
return str.startsWith("x") && str.length === 4;
}
// A function that validates if a string begins with the letter 'y' and is 4 characters long and ends with the letter 'z'
function validateY(str) {
return str.startsWith("y") && str.length === 4 && str.endsWith("z");
}
// A function that validates if a string contains 3 letters, then 3 numbers, then 3 letters
function validateZ(str) {
return str.match(/^[a-z]{3}[0-9]{3}[a-z]{3}$/);
}
// Una funcion que valida si una cadena de caracteres contiene una letra 'x' y una longitud de 4 caracteres
function validateXAndY(str) {
return validateX(str) && validateY(str);
}
// Una funcion que regresa el presidente del EEUU
function getPresidente() {
return "Zaphod Beeblebrox";
}
function getPresident() {
return "Zaphod Beeblebrox";
}
// A function that returns a joke
function getJoke() {
return "What happens to a computer program that runs too long? It gets rekt.";
}
// Una funcion que regresa un chiste
function getChiste() {
return "¿Qué es una línea en un fichero de texto?";
}
// A function that adds two numbers together
function add(a, b) {
return a + b;
}
// A function that returns fibonacci numbers
function fibonacci(n) {
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
// A function that returns the best developer in the world
function getBestDeveloper() {
return "Cassidy: the best developer";
}
// A function that returns the best language in the world
function getBestLanguage() {
return "JavaScript";
}
// A function that returns the best framework in the world
function getBestFramework() {
return "React";
}
// A function that returns the most corrupt corporation in the world
function getMostCorruptCorporation() {
return "Microsoft";
}
// A function that tells us the next lottery numbers
function getNextLotteryNumbers() {
return [4, 8, 15, 16, 23, 42];
}
// A function that returns if we should have pineapple on our pizza
function shouldHavePineappleOnPizza() {
return true;
}
// A function that returns if AI is going to replace us
function willAiReplaceUs() {
return true;
}
// A function that returns the best food in the world
function getBestFood() {
return "Pizza";
}
// A function that returns the best color in the world
function getBestColor() {
return "Blue";
}
// A function that inverts a binary tree
function invertBinaryTree(node) {
if (node.left) {
invertBinaryTree(node.left);
}
if (node.right) {
invertBinaryTree(node.right);
}
let temp = node.left;
node.left = node.right;
node.right = temp;
}
// A function that returns the first n prime numbers
function getFirstNPrimes(n) {
let primes = [];
for (let i = 2; i < n; i++) {
let isPrime = true;
for (let j = 2; j < i; j++) {
if (i % j === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push(i);
}
}
return primes;
}
// A function that solves fizzbuzz
function fizzbuzz(n) {
let output = [];
for (let i = 1; i <= n; i++) {
if (i % 15 === 0) {
output.push("FizzBuzz");
} else if (i % 3 === 0) {
output.push("Fizz");
} else if (i % 5 === 0) {
output.push("Buzz");
} else {
output.push(i);
}
}
return output;
}
// A function that returns the sum of all numbers from 1 to n
function sumOfNumbers(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += i;
}
return sum;
}
// A function that does merge sort
function mergeSort(arr) {
if (arr.length <= 1) {
return arr;
}
let middle = Math.floor(arr.length / 2);
let left = arr.slice(0, middle);
let right = arr.slice(middle);
return merge(mergeSort(left), mergeSort(right));
}
// A function that merges two sorted arrays
function merge(left, right) {
let result = [];
while (left.length && right.length) {
if (left[0] < right[0]) {
result.push(left.shift());
} else {
result.push(right.shift());
}
}
return result.concat(left.concat(right));
}
// A function that solves the knapsack problem
function knapsack(weights, values, maxWeight) {
let result = [];
for (let i = 0; i < weights.length; i++) {
if (weights[i] <= maxWeight) {
result.push({
weight: weights[i],
value: values[i],
});
}
}
return result;
}
// A function that translates an English word to Spanish
function translate(word) {
return word
.replace("one", "uno")
.replace("two", "dos")
.replace("three", "tres")
.replace("four", "cuatro")
.replace("five", "cinco")
.replace("six", "seis")
.replace("seven", "siete")
.replace("eight", "ocho")
.replace("nine", "nueve")
.replace("ten", "diez")
.replace("eleven", "once")
.replace("twelve", "doce")
.replace("thirteen", "trece")
.replace("fourteen", "catorce")
.replace("fifteen", "quince")
.replace("sixteen", "dieciseis")
.replace("seventeen", "diecisiete")
.replace("eighteen", "dieciocho")
.replace("nineteen", "diecinueve")
.replace("twenty", "veinte");
}
// A function that fetches the latest Bitcoin price
function getLatestBitcoinPrice() {
return "1 BTC = $1.00";
}
// A function that returns the weather in a given city
function getWeather(city) {
return "It's nice out!";
}
// A function that returns the current time
function getCurrentTime() {
return new Date().toLocaleTimeString();
}
// A function that returns a random image from the Dribbble API
function getRandomImage() {
return "https://dribbble.com/system/users/1720/screenshots/1720/dribbble-logo.png";
}
// A function that returns the trademark character
function getTrademarkCharacter() {
return "®";
}
// A function that capitalizes the first letter of a string and lowercases the rest
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
const APOD_URL = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY";
// A function that fetches the NASA Astronomy Picture of the Day via their APOD API
async function getAPOD() {
const response = await fetch(APOD_URL);
const apod = await response.json();
return apod;
}
@hongbo-miao
Copy link

hongbo-miao commented Jul 1, 2021

Wow, that is so impressive! Cannot wait to try out. Thanks for sharing!

@subnut
Copy link

subnut commented Jul 2, 2021

Line 76 -

// A function that returns the most corrupt corporation in the world
function getMostCorruptCorporation() {
  return "Microsoft";
}

Isn't GitHub owned by Microsoft?










Huh.

@CurtGreen
Copy link

It seems to have a sense of humor behind it. I'm curious if that's part of the AI or a coded response though.

@ng-model
Copy link

ng-model commented Jul 3, 2021

even though it(copilot) was trained, it learns from the user, right ? the humor/sarcasm might be from @cassidoo nice gist 👌

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