Skip to content

Instantly share code, notes, and snippets.

@dmi3y
Last active December 24, 2018 04:09
Show Gist options
  • Select an option

  • Save dmi3y/f24979b888c91721b8041ab11d9e61f1 to your computer and use it in GitHub Desktop.

Select an option

Save dmi3y/f24979b888c91721b8041ab11d9e61f1 to your computer and use it in GitHub Desktop.

Revisions

  1. dmi3y revised this gist Dec 24, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ const christmasPresentsPerDaysRec = (days = 12, day = 1, collect = [0]) => {
    }
    }

    const argvDays = process.argv.length > 2 ? process.argv.pop() : 3
    const argvDays = process.argv.length > 2 ? process.argv.pop() : 12
    console.log(christmasPresentsPerDays(argvDays) )
    console.log(christmasPresentsPerDaysRec(argvDays))
    console.log(`For ${argvDays} days you got ${christmasPresentsPerDays(argvDays)} presents!`)
  2. dmi3y revised this gist Dec 24, 2018. 1 changed file with 15 additions and 10 deletions.
    25 changes: 15 additions & 10 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,31 @@
    #!/usr/bin/env node

    const sumit = (sum, it) => sum + it
    // Christmas is around us!
    const christmasPresentsPerDays = (days = 12) => {
    const bag = [];
    for (let i = 0; i < days; i++) {
    bag.push(i + 1 + bag[i - 1] || 1);
    }
    return bag.reduce((sum, it) => sum + it, 0);
    return bag.reduce(sumit, 0);
    }

    const christmasPresentsPerDaysRec = (days = 12) => {
    if (days > 1 ) {
    return days + christmasPresentsPerDaysRec(days - 1)
    const christmasPresentsPerDaysRec = (days = 12, day = 1, collect = [0]) => {
    if (day > days){
    day
    collect
    return collect.reduce(sumit)
    } else {
    return 1
    day
    collect
    let nsum = collect.reduce(sumit) + day
    collect.push(nsum)
    let nday = day + 1
    return christmasPresentsPerDaysRec(days, nday, collect)
    }
    }

    const argvDays = process.argv.length > 2 ? process.argv.pop() : 2
    const argvDays = process.argv.length > 2 ? process.argv.pop() : 3
    console.log(christmasPresentsPerDays(argvDays) )
    console.log(christmasPresentsPerDaysRec(argvDays))
    console.log(`For ${argvDays} days you got ${christmasPresentsPerDaysRec(argvDays)} presents!`)

    let sum = 2 * 3 - 1 + (2 * 2 - 1 + (1))
    sum
    console.log(`For ${argvDays} days you got ${christmasPresentsPerDays(argvDays)} presents!`)
  3. dmi3y revised this gist Dec 24, 2018. 1 changed file with 16 additions and 2 deletions.
    18 changes: 16 additions & 2 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -8,5 +8,19 @@ const christmasPresentsPerDays = (days = 12) => {
    }
    return bag.reduce((sum, it) => sum + it, 0);
    }
    const argvDays = process.argv.length > 2 ? process.argv.pop() : 12
    console.log(`For ${argvDays} days you got ${christmasPresentsPerDays(argvDays)} presents!`)

    const christmasPresentsPerDaysRec = (days = 12) => {
    if (days > 1 ) {
    return days + christmasPresentsPerDaysRec(days - 1)
    } else {
    return 1
    }
    }

    const argvDays = process.argv.length > 2 ? process.argv.pop() : 2
    console.log(christmasPresentsPerDays(argvDays) )
    console.log(christmasPresentsPerDaysRec(argvDays))
    console.log(`For ${argvDays} days you got ${christmasPresentsPerDaysRec(argvDays)} presents!`)

    let sum = 2 * 3 - 1 + (2 * 2 - 1 + (1))
    sum
  4. dmi3y revised this gist Dec 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -9,4 +9,4 @@ const christmasPresentsPerDays = (days = 12) => {
    return bag.reduce((sum, it) => sum + it, 0);
    }
    const argvDays = process.argv.length > 2 ? process.argv.pop() : 12
    console.log(`For ${argvDays} you got ${christmasPresentsPerDays(argvDays)} presents!`)
    console.log(`For ${argvDays} days you got ${christmasPresentsPerDays(argvDays)} presents!`)
  5. dmi3y revised this gist Dec 22, 2018. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -9,5 +9,4 @@ const christmasPresentsPerDays = (days = 12) => {
    return bag.reduce((sum, it) => sum + it, 0);
    }
    const argvDays = process.argv.length > 2 ? process.argv.pop() : 12
    console.log(argvDays, 'days')
    console.log(christmasPresentsPerDays(argvDays))
    console.log(`For ${argvDays} you got ${christmasPresentsPerDays(argvDays)} presents!`)
  6. dmi3y revised this gist Dec 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,6 @@ const christmasPresentsPerDays = (days = 12) => {
    }
    return bag.reduce((sum, it) => sum + it, 0);
    }
    const argvDays = process.argv > 2 ? process.argv.pop() : 12
    const argvDays = process.argv.length > 2 ? process.argv.pop() : 12
    console.log(argvDays, 'days')
    console.log(christmasPresentsPerDays(argvDays))
  7. dmi3y revised this gist Dec 22, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -9,4 +9,5 @@ const christmasPresentsPerDays = (days = 12) => {
    return bag.reduce((sum, it) => sum + it, 0);
    }
    const argvDays = process.argv > 2 ? process.argv.pop() : 12
    console.log(argvDays, 'days')
    console.log(christmasPresentsPerDays(argvDays))
  8. dmi3y revised this gist Dec 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -8,5 +8,5 @@ const christmasPresentsPerDays = (days = 12) => {
    }
    return bag.reduce((sum, it) => sum + it, 0);
    }
    const = argvDays = process.argv > 2 ? process.argv.pop() : 12
    const argvDays = process.argv > 2 ? process.argv.pop() : 12
    console.log(christmasPresentsPerDays(argvDays))
  9. dmi3y revised this gist Dec 22, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -8,5 +8,5 @@ const christmasPresentsPerDays = (days = 12) => {
    }
    return bag.reduce((sum, it) => sum + it, 0);
    }

    console.log(christmasPresentsPerDays(), process.argv)
    const = argvDays = process.argv > 2 ? process.argv.pop() : 12
    console.log(christmasPresentsPerDays(argvDays))
  10. dmi3y revised this gist Dec 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -9,4 +9,4 @@ const christmasPresentsPerDays = (days = 12) => {
    return bag.reduce((sum, it) => sum + it, 0);
    }

    console.log(christmasPresentsPerDays())
    console.log(christmasPresentsPerDays(), process.argv)
  11. dmi3y revised this gist Dec 22, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -8,3 +8,5 @@ const christmasPresentsPerDays = (days = 12) => {
    }
    return bag.reduce((sum, it) => sum + it, 0);
    }

    console.log(christmasPresentsPerDays())
  12. dmi3y revised this gist Dec 22, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    // Christmas is around us!
    #!/usr/bin/env node

    // Christmas is around us!
    const christmasPresentsPerDays = (days = 12) => {
    const bag = [];
    for (let i = 0; i < days; i++) {
  13. dmi3y revised this gist Dec 22, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {"name": "12-days-of-christmas", "version": "0.0.0", "bin": "./12daysOfChristmas.js"}
  14. dmi3y revised this gist Dec 22, 2018. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,9 @@
    // Christmas is around us!

    const christmasPresentsPerDays = days => {
    const christmasPresentsPerDays = (days = 12) => {
    const bag = [];
    for (let i = 0; i < days; i++) {
    bag.push(i + 1 + bag[i - 1] || 1);
    }
    return bag.reduce((sum, it) => sum + it, 0);
    };

    const presents = christmasPresentsPerDays(12);
    return presents
    }
  15. dmi3y revised this gist Dec 22, 2018. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,12 @@
    // Christmas is around us!

    const christmasPresentsPerDays = (days) => {
    const christmasPresentsPerDays = days => {
    const bag = [];
    for (let i = 0; i < days; i++) {
    bag.push(i + 1 + bag[i - 1] || 1);
    }
    return bag.reduce((sum, it) => sum + it, 0);
    };

    }

    christmasPresentsPerDays(1)
    const presents = christmasPresentsPerDays(12);
    return presents
  16. dmi3y revised this gist Dec 22, 2018. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -1 +1,7 @@
    // Christmas is around us!
    // Christmas is around us!

    const christmasPresentsPerDays = (days) => {

    }

    christmasPresentsPerDays(1)
  17. dmi3y created this gist Dec 22, 2018.
    1 change: 1 addition & 0 deletions 12daysOfChristmas.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    // Christmas is around us!