View curry.js
function curry( fn ) {
var arity = fn.length;
return (function resolver() {
var mem = Array.prototype.slice.call( arguments );
return function() {
var args = mem.slice();
Array.prototype.push.apply( args, arguments );
return ( args.length >= arity ? fn : resolver ).apply( null, args );
};
View jogadeenhas.js
const byASC = ( a, b ) => a - b
const play = ( bets ) => {
const betsSorted = bets.sort( byASC )
let PLAY = true
let i = 1
console.log('JOGADA: ', i )
console.log('player1: ', betsSorted[ 0 ] )
console.log('player2: ', betsSorted[ 1 ] )
console.log('\n' )
View nestedSquareRoots.js
/**
Consider the term x+y√+z√−−−−−−−−−−−√x+y+z that is representing a
nested square root. xx, yy and zz are positive integers and yy and zz are
not allowed to be perfect squares, so the number below the outer square
root is irrational. Still it can be shown that for some combinations of
xx, yy and zz the given term can be simplified into a sum and/or difference
of simple square roots of integers, actually denesting the square roots in
the initial expression.
You are given that F(10)=17, F(15)=46, F(20)=86,
View largest.prime.fac.js
// The prime factors of 13195 are 5, 7, 13 and 29.
// What is the largest prime factor of the number 600851475143 ?
const NUM = 600851475143
const getLength = ( n ) => Math.floor( Math.sqrt( n ) ) - 1
const isPrime = ( n ) =>
( n > 1 && Array.from( { length: getLength( n ) }, ( v, k ) => k + 2 )
.every( m => n % m )
View largest.prime.fac.js
// The prime factors of 13195 are 5, 7, 13 and 29.
// What is the largest prime factor of the number 600851475143 ?
const NUM = 600851475143
const getLength = ( n ) => Math.floor( Math.sqrt( n ) ) - 1
const isPrime = ( n ) =>
( n > 1 && Array.from( { length: getLength( n ) }, ( v, k ) => k + 2 )
.every( m => n % m )
View teste.inscricao.estadual.js
'use strict'
const fs = require( 'fs' )
const inscricaoEstadual = require( '../ie' )
const tests = fs.readdirSync( './testes' )
const getFilesToTest = ( tests ) =>
tests.filter( name => name.length === 5 )
.map( name => name.substr( 0, 2 ) )
View primo.odiegoprado.js
var primo = function(n){
if (!isNaN(n)) {
if (n != 1) {
for (i = 2; i < n; i++) {
if(n % i == 0){
return false;
}
}
return n !== 1;
}
View fold.js
/*eslint-env es6 */
// Inspired by the paper "A tutorial on the universality and
// expressiveness of fold" by Graham Hutton ( available at
// http://www.cs.nott.ac.uk/~gmh/fold.pdf ), implementing some generic
// list handling functions in JavaScript in terms of `fold`.
// Personally I had an enlightnening moment when I realised the
// beautiful interplay of cons lists and foldr during the FP101x
// Haskell course. JavaScript's syntax doesn't make this very apparent
View angular.service.dum.aluno.js
const MSG = {
dontUpdate: ( usuario ) => ({
mensagem: 'Não foi possível atualizar o usuario ' + usuario.login
}),
dontInsert: ( usuario ) => ( {
mensagem: 'Não foi possível incluir o usuario ' + usuario.login
} ),
update: ( usuario ) => ( {
mensagem: 'Usuario ' + usuario.login + ' atualizada com sucesso',
inclusao: false
View cpf.validate.almost.final.js
const mod11 = ( num ) => num % 11
const NOT = ( x ) => !x
const isEqual = ( a ) => ( b ) => b === a
const mergeDigits = ( num1, num2 ) => `${num1}${num2}`
const getTwoLastDigits = ( cpf ) => `${cpf[ 9 ]}${cpf[ 10 ]}`
const getCpfToCheckInArray = ( cpf ) => cpf.substr( 0, 9 ).split( '' )
const generateArray = ( length ) => Array.from( { length }, ( v, k ) => k )
const isIn = ( list ) => ( value ) =>
list.findIndex( v => value === v ) >= 0