Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace npm package dependency sprintf -> sprintf-js #191

Open
todd-dsm opened this issue Mar 25, 2018 · 3 comments
Open

Replace npm package dependency sprintf -> sprintf-js #191

todd-dsm opened this issue Mar 25, 2018 · 3 comments

Comments

@todd-dsm
Copy link

npm complained on the install:

$ npm install -g functional-javascript-workshop@latest
npm WARN deprecated sprintf@0.1.5: The sprintf package is deprecated in favor of sprintf-js.
/usr/local/bin/functional-javascript -> /usr/local/lib/node_modules/functional-javascript-workshop/functional-javascript.js
/usr/local/bin/functional-javascript-workshop -> /usr/local/lib/node_modules/functional-javascript-workshop/functional-javascript.js
+ functional-javascript-workshop@1.0.6
added 68 packages from 30 contributors in 3.289s

We'll know shortly if this is a technical complaint and everything still works - or not.

@RavenHursT
Copy link

RavenHursT commented Apr 11, 2018

I can't get through Exercise 8(Call) due to, what seems to be, based on the error message, this deprecated sprintf package:

$ fjs run 8.js
/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:163
					throw new Error(sprintf('[sprintf] expecting number but found %s "' + arg + '"', get_type(arg)));
					^

Error: [sprintf] expecting number but found undefined "undefined"
    at str_format.format (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:163:12)
    at str_format (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:77:28)
    at Object.vsprintf (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:244:17)
    at _defaultTranslation (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/node_modules/i18n-core/index.js:28:15)
    at Object.defaultTranslation (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/node_modules/i18n-core/index.js:34:9)
    at Object.__ (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/node_modules/i18n-core/lib/createTranslator.js:30:15)
    at /usr/local/lib/node_modules/functional-javascript-workshop/exercises/basic_call/exercise.js:56:19
    at obtainResult (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:100:21)
    at Exercise.<anonymous> (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:66:27)
    at next (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:188:19)

I've set up an alias for functional-javascript.

What's odd.. is that once I run this.. all the rest of my previous exercises stop working as well:

$ fjs run 7.js
/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:163
					throw new Error(sprintf('[sprintf] expecting number but found %s "' + arg + '"', get_type(arg)));
					^

Error: [sprintf] expecting number but found undefined "undefined"
    at str_format.format (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:163:12)
    at str_format (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:77:28)
    at Object.vsprintf (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:244:17)
    at _defaultTranslation (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/node_modules/i18n-core/index.js:28:15)
    at Object.defaultTranslation (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/node_modules/i18n-core/index.js:34:9)
    at Object.__ (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/node_modules/i18n-core/lib/createTranslator.js:30:15)
    at /usr/local/lib/node_modules/functional-javascript-workshop/exercises/basic_call/exercise.js:56:19
    at obtainResult (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:100:21)
    at Exercise.<anonymous> (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:66:27)
    at next (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:188:19)

$ fjs run 6.js
/Users/matthewmarcus/dev/functional-js/6.js:2
  return inputWords.reduce((agg, word) => {
                    ^

TypeError: inputWords.reduce is not a function
    at countWords (/Users/matthewmarcus/dev/functional-js/6.js:2:21)
    at /usr/local/lib/node_modules/functional-javascript-workshop/exercises/basic_call/exercise.js:56:44
    at obtainResult (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:100:21)
    at Exercise.<anonymous> (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:66:27)
    at next (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:188:19)
    at /usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:195:7
    at Exercise.<anonymous> (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:34:5)
    at next (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:188:19)
    at /usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:195:7
    at /usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/execute.js:110:7

If I run functional-javascript-workshop again, and "go back" to the 7th test.. it works again :/

$ fjsws


    FUNCTIONAL JAVASCRIPT IS GOOD
    Select an exercise and hit Enter to begin
    ─────────────────────────────────────────────────────────────────
    » Hello World                                [COMPLETED]
    » Higher Order Functions                     [COMPLETED]
    » Basic: Map                                 [COMPLETED]
    » Basic: Filter                              [COMPLETED]
    » Basic: Every Some                          [COMPLETED]
    » Basic: Reduce                              [COMPLETED]
    » Basic: Recursion                           [COMPLETED]
    » Basic: Call
    » Partial Application without Bind
    » Partial Application with Bind
    » Implement Map with Reduce
    » Function Spies
    » Blocking Event Loop
    » Trampoline
    » Async Loops
    » Recursion
    » Currying
    » Function Call
    ─────────────────────────────────────────────────────────────────
    HELP
    CHOOSE LANGUAGE
    EXIT


 FUNCTIONAL JAVASCRIPT IS GOOD
───────────────────────────────
 Basic: Recursion
 Exercise 7 of 18

Recursion is a fundamental programming concept which can lead to elegant and efficient solutions to algorithmic problems. In fact, recursion is so powerful, all iterating behaviour can be defined using recursive functions. You will find recursion indispensable when iterating over nested data structures.

A recursive function is a function which calls itself. For example, this recursive function will take an array of words, and return an array of those words, uppercased.

    function toUpperArray(items) {
       if (!items.length) return []             // end condition
       var head = items[0]                      // item to operate on
       head = head.toUpperCase()                // perform action
       var tail = items.slice(1)                // next
       return [head].concat(toUpperArray(tail)) // recursive step
    }

    toUpperArray(['hello', 'world']) // => ['HELLO', 'WORLD']

The point of this exercise is to familiarise yourself with recursion by implementing a familiar interface using a recursive function.

# Task

Implement Array#reduce using recursion.

To test your reduction works correctly we will use your reduce implementation to execute our solution to the previous basic_reduce problem. i.e. your reduce function will be passed an array of words, and a function, and an initial value which will return an object containing the counts for each word found in the array. You don't need to implement this functionality, it will be supplied to your reduce implementation.

For simplicity, your implementation of reduce need not replicate the behaviour of a reduce missing an initial value. You may assume the initial value will always be supplied.

## Arguments

  * arr: An Array to reduce over
  * fn: Function to use as the reduction step. Like regular Array#reduce, this function must be passed previousValue, currentValue, index and the array we're iterating over.
  * init: Initial value of the reduction. Unlike Array#reduce, this value is required (and you may assume it will always be supplied).

## Example

    // Your reduce function should behave the same as a
    // regular Array#reduce, but it will take the array
    // to operate on as the first argument:

    reduce([1,2,3], function(prev, curr, index, arr) {
      return prev + curr
    }, 0)
    // => 6

## Conditions

  * Do not use any for/while loops.
  * Do not use any Array methods like Array#map or Array#reduce.

## Resources

  * https://en.wikipedia.org/wiki/Recursion
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

## Boilerplate

    function reduce(arr, fn, initial) {
      // SOLUTION GOES HERE
    }

    module.exports = reduce


 » To print these instructions again, run: functional-javascript print
 » To execute your program in a test environment, run: functional-javascript run program.js
 » To verify your program, run: functional-javascript verify program.js
 » For help run: functional-javascript help


$ fjs run 7.js
input:      [ 'laboris', 'deserunt', 'id', 'culpa', 'id', 'eiusmod', 'aliquip', 'do', 'cillum', 'qui', 'proident', 'velit', 'duis', 'dolore', 'deserunt', 'pariatur', 'lorem', 'enim', 'exercitation', 'enim', 'reprehenderit', 'non', 'consectetur', 'commodo', 'cillum', 'duis', 'magna', 'velit', 'officia', 'do', 'eiusmod', 'quis', 'dolor', 'fugiat', 'deserunt', 'aliqua', 'dolor', 'ea', 'irure', 'occaecat', 'deserunt', 'dolore', 'veniam', 'in' ]
submission: { laboris: 1, deserunt: 4, id: 2, culpa: 1, eiusmod: 2, aliquip: 1, do: 2, cillum: 2, qui: 1, proident: 1, velit: 2, duis: 2, dolore: 2, pariatur: 1, lorem: 1, enim: 2, exercitation: 1, reprehenderit: 1, non: 1, consectetur: 1, commodo: 1, magna: 1, officia: 1, quis: 1, dolor: 2, fugiat: 1, aliqua: 1, ea: 1, irure: 1, occaecat: 1, veniam: 1, in: 1 }

Something's most definitely broken w/ this package....

@RavenHursT
Copy link

Pretty sure my solution is right too :/

https://repl.it/@RavenHursT/Functional-JS-Workshop-Exercise-8-Solution

@RavenHursT
Copy link

Arg.. can't skip and go on to 9 either :-/

$ fjs run 9.js
/usr/local/lib/node_modules/functional-javascript-workshop/exercises/partial_application_without_bind/wrapper.js:16
  if (i % 2 === 0) info.apply(null, message.split(' '))
                        ^

TypeError: Cannot read property 'apply' of undefined
    at /usr/local/lib/node_modules/functional-javascript-workshop/exercises/partial_application_without_bind/wrapper.js:16:25
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/partial_application_without_bind/wrapper.js:15:7)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants