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

tkolleh • 3 years ago

Is the spread operator not supported? `{ ...item }`

Lee Grobler • 2 years ago

Where can we find the answers to the exercises?? The software that tests what we write seems to be buggy. I couldn't pass hte isNotPrime test until I manually copied and pasted my `isPrime` function from the previous exercise. Now I'm again not passing the manual implementation of `reject` and because it's hurt me before I now can't tell if my code is bad, or if the software that's testing the exercises is garbo.

AndroidRaccoon • 1 year ago

Yeah I figured out that stuffs are weird. For whoever finds this comment, the issue is because the line

const isPrime = require('./isPrime.js'); // our previous snippet

Will require the whole file. So to use the actual function you need to do isPrime.isPrime() (which is dumb).

A nicer way is to change the l2 into :

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

The brackets will target the actual function.

dquindara8 • 1 year ago

Hello everyone. I would really appreciate your help with this code. I am stuck and don't know how to get it to run. Can anyone help me please? Thanks.

The cart is an array of objects like this:
var cart=[
{"name":"Biscuits", "type":"regular", "category":"food", "price": 2.0},
{"name":"Monitor", "type":"prime", "category":"tech", "price": 119.99},
{"name":"Mouse", "type":"prime", "category":"tech", "price": 25.50},
{"name":"dress", "type":"regular", "category":"clothes", "price": 49.90},
function isPrime(item){
return item + "type";

function primeItems(cart){
return "type" + cart;
const cart = ['Buscuits', 'Monitor', 'Mouse', 'dress'];
const cartItems = cart.filter(primeItems);

// {
module.exports = {
primeItems: primeItems,
isPrime: isPrime
// }

Anonymous • 4 years ago

Hi there. Thanks for creating this resource. I've been stuck for quite some time (and only the 2nd Page, yikes) the code I have for coupon.js returns an error on this test but seems to work fine in JS Bin. I really can'r see what I'm missing. Can anyone shed light on it for me?

Here's my code:

function applyCoupon(cart){
// write your code here let discount = (x) =>

// filter the tech items
let discountedProducts = cart
.filter((product) => {
return product.category === 'tech'
}).map((product) => {
return ( product.price - (product.price * 0.2) ).toFixed(2)

return discountedProducts


Andrea • 4 years ago

you are returning only the tech items, but the function should return all items in the cart

Pilar • 4 years ago

great stuff thanks

Annex00 • 6 years ago

Hi, awesome course!


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 • 6 years ago


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 • 6 years ago

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

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

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

Arkentias • 6 years 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 • 6 years ago

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

Ivan Szabo • 6 years 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 • 6 years 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 = {}
.filter(x => x.parent === parent)
.forEach(x => {
node[x.id] = buildTree(list, x.id)
return node

Bascule • 6 years ago

Thanks for your answer. I really like it.

LiubomirCH • 6 years 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 • 6 years 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


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

LiubomirCH • 6 years 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');
Lee Grobler • 2 years ago

4 years and he still hasn't updated it.