---
# System prepended metadata

title: In Class Studio 6

---

# In Class Studio 6

## Question 1.
Write a function called `remove_duplicates` that takes in a list as its only argument and returns a list with duplicate elements removed. The order of the elements in the returned list does not matter. Use `accumulate` in your function.

Example Call:
```javascript
function remove_duplicates(lst) {
    return accumulate((x, y) => is_null(member(x, y)) 
                                    ? pair(x, y)
                                    : y, null, lst); 
}


```

## Question 2.
In this question, lists represent sets. Each element of the set appears exactly once in its list representation, and the order does not matter. So the list `list(1, 2, 3)` represents the same set as the list `list(3, 2, 1)`. In this question, you are supposed to compute all subsets of a give set. Your function subsets takes as argument a list, representing the given set, and needs to return a list of lists, each representing a unique subset of the given set.

Example Call:
```javascript
subsets(list(1, 2, 3));
// Result: list(list(),
//              list(1), list(2), list(3),
//              list(1,2), list(1,3), list(2,3),
//              list(1,2,3))

```

```javascript=
function subsets(xs) {
    // base case
    if (is_null(xs)) {
        return list(null);
    }
    else {
        // display("start");
        // display(head(xs));
        
        //subsets excluding head
        const excl_head = subsets(tail(xs));
        //subsets including head
        const incl_head = map(argxs => append(list(head(xs)), argxs), excl_head);
        // make a copy of all current subsets, append them tgt, with the new ones + current head
        // display("after incl");
        
        // display(append(list(head(xs)), excl_head));
        // display(append(list(head(xs)), "HI"));
        // display(append(incl_head, excl_head));
        
        return append(incl_head, excl_head);
    }
}
```

## Question 3.
A permutation of a list s is a list with the same elements as s, but in a possibly different order. For example, the list `list(3,1,2)` is a permutation of `list(1,2,3)`. Write a function permutations that takes a list s as argument and returns a list of all permutations of s.

```javascript
permutations(list(1, 2, 3));
// Result: list(list(1,2,3), list(1,3,2),
//              list(2,1,3), list(2,3,1),
//              list(3,1,2), list(3,2,1))
```

```javascript=
function permutations(s) {
    // Your Answer Here
}
```