This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
primes = filterPrime [2..] | |
where filterPrime (p:xs) = | |
p : filterPrime [x | x <- xs, x `mod` p /= 0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template<int n> | |
struct facto | |
{ | |
static constexpr unsigned int value = n * facto<n - 1>::value; | |
}; | |
template<> | |
struct facto<0> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstddef> | |
template<typename T> | |
struct IsArray | |
{ | |
static constexpr bool value = false; | |
}; | |
template<typename T> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const palindrome = str => { | |
const s = str.toLowerCase().replace(/[\W_]/g, ''); | |
return s === s.split('').reverse().join(''); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reverseString = str => [...str].reverse().join(''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param {string} text | |
* | |
* Return a plain JS object providing the number of occurrences of every word containing at least 3 characters from the text | |
*/ | |
const wordOccurrences = (text) => { // functional programming version | |
return text | |
.split(' ') | |
.filter((token) => token.length > 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ApolloServer, gql } = require('apollo-server') | |
// The GraphQL schema | |
const typeDefs = gql` | |
type Query { | |
"A simple type for getting started!" | |
foo: String | |
foofoo: Int | |
} | |
` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const filename = pathname.replace(/^.*[\\\/]/g, '') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const seconds = time => time // formatted as 'HH:MM:SS' | |
.split(':') | |
.reverse() | |
.reduce((acc, val, i) => acc + val * 60 ** i, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.annotation.tailrec | |
def recursiveSum(f: Int => Int)(a: Int, b: Int): Int = { | |
if (a > b) | |
0 | |
else | |
f(a) + recursiveSum(f)(a + 1, b) | |
} | |
def tailRecursiveSum(f: Int => Int)(a: Int, b: Int): Int = { |
OlderNewer