We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Annex00 • 1 year ago

Hi, awesome course!

EDIT: OK FIGURED IT OUT!

could you please tell what's wrong in the following code?

function applyCoupon(cart) {
return cart.map(function (el) {
if (el.category == "tech") {
return el.price * 0.8;
}
return el.price;
})
}

Martin Vandersteen • 1 year ago

Hello,

On page 2, last exercise, I get this error :

1) tests: should return the prime items:
TypeError: totalCost.totalCost is not a function
at Context.<anonymous> (higher/totalCost.spec.js:39:49)

With this code (which works flawlessly in Chrome console) :

function totalCost(cart){
const callback = (acc, x) => {
return acc + x.price;
};
return cart.reduce(callback, 0);
}

(I'm probably doing something wrong though)
All problems aside thanks for this really cool tutorial !

Andrea Zanin • 1 year ago

You probably accidentally removed the line that exports your function.
The correct code is

```js
function totalCost(cart){
const callback = (acc, x) => {
return acc + x.price;
};
return cart.reduce(callback, 0);
}

// { autofold
module.exports = {
totalCost: totalCost
};
// }
```

Arkentias • 1 year ago

Perfect it works ! Never saw that piece of code, I probably CTRL-A + backspaced all of it out :p

Great tutorial series thank you :)

AndreaZanin • 1 year ago

I hate that you have to insert that, but sadly there is no way around

Ivan Szabo • 1 year ago

Hello Andrea,

thanks for creating this introduction.
I enjoyed it until the recursion task (bottom of page 4). In my opinion this is a huge increase in difficulty, compared to the previous steps and the examples. The guidance you provide on this page was unfortunately not enough for me.
Having spent a few unsuccessful hours on this problem, is there a way you could share a functional solution? I'm sure I could learn from it.
Thanks in advance!

Andrea Zanin • 1 year ago

Here is a solution, as many found the problem hard I will link the solution in the playground

```
const buildTree = (list, parent) => {
var node = {}
list
.filter(x => x.parent === parent)
.forEach(x => {
node[x.id] = buildTree(list, x.id)
})
return node
}
```

Bascule • 1 year ago

Thanks for your answer. I really like it.

LiubomirCH • 1 year ago

Hello, Andrea!
Code "return _.reject(cart, isPrime)" in notPrimeItems doesn't work. But when I'm writing this as callback "return _.reject(cart, (item) => item.type === 'prime')" it passes all test. Something wrong with tests? Or I'm doing something wrong?

AndreaZanin • 1 year ago

Hi, the line

const isPrime = require('./isPrime.js');

imports the file you created, but to call the function `isPrime` within that file you have to write

isPrime.isPrime

, sorry for the confusion I'll clarify that in the playground as soon as possible.

LiubomirCH • 1 year ago

Thanks for reply, I didn't noticed that an object is exported :) The object destructuring can be used here as well:

const { isPrime } = require('./isPrime.js');