◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
describe("unique", function() {
it("removes non-unique elements", function() {
let strings = ["Hare", "Krishna", "Hare", "Krishna",
"Krishna", "Krishna", "Hare", "Hare", ":-O"
];

assert.deepEqual(unique(strings), ["Hare", "Krishna", ":-O"]);
});

it("does not change the source array", function() {
let strings = ["Krishna", "Krishna", "Hare", "Hare"];
unique(strings);
assert.deepEqual(strings, ["Krishna", "Krishna", "Hare", "Hare"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ function intersection(arr1, arr2) {
return arr1.filter(item => arr2.includes(item));
}

describe("aclean", function() {

it("returns exactly 1 word from each anagram set", function() {
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];

let result = aclean(arr);
Expand All @@ -16,7 +16,7 @@ describe("aclean", function() {

});

it("is case-insensitive", function() {
let arr = ["era", "EAR"];
assert.equal(aclean(arr).length, 1);
});
12 changes: 6 additions & 6 deletions 1-js/05-data-types/07-map-set/02-filter-anagrams/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ importance: 4

---

# Filter anagrams

[Anagrams](https://en.wikipedia.org/wiki/Anagram) are words that have the same number of same letters, but in different order.

For instance:

```
nap - pan
ear - are - era
cheaters - hectares - teachers
```

Write a function `aclean(arr)` that returns an array cleaned from anagrams.

For instance:

```js
let arr = ["nap", "teachers", "cheaters", "PAN", "ear", "era", "hectares"];

alert( aclean(arr) ); // "nap,teachers,ear" or "PAN,cheaters,era"
```

From every anagram group should remain only one word, no matter which one.

4 changes: 2 additions & 2 deletions 1-js/05-data-types/07-map-set/03-iterable-keys/solution.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

That's because `map.keys()` returns an iterable, but not an array.

We can convert it into an array using `Array.from`:


```js run
Expand Down
10 changes: 5 additions & 5 deletions 1-js/05-data-types/07-map-set/03-iterable-keys/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Iterable keys

We'd like to get an array of `map.keys()` in a variable and then apply array-specific methods to it, e.g. `.push`.

But that doesn't work:

```js run
let map = new Map();
Expand All @@ -16,9 +16,9 @@ map.set("name", "John");
let keys = map.keys();

*!*
// Error: keys.push is not a function
keys.push("more");
*/!*
```

Why? How can we fix the code to make `keys.push` work?
Loading
Toggle all file notes Toggle all file annotations