Project Euler Problem #8

in code


Functional JavaScript is cleaner than my C# solution, for sure!

const raw = '731..450'; // Snipped for clarity.
const chunkSize = 13;
const multiply = (previous, current) => previous * current;
const largest = (previous, current) => current > previous ? current : previous;

function chop(string, size, chunks) {
    chunks = chunks || [];

    if (!string || string.length < size) {
        return chunks;
    }

    return chunks.concat(string.slice(0, size), chop(string.slice(1), size, chunks));
}

chop(rawString, chunkSize).map(str => str.split('').reduce(multiply)).reduce(largest);


A Summer of Running

in running

Achill Half Marathon

in running


Your email address will not be published. Required fields are marked *