Skip to content

Commit fe9950e

Browse files
committed
Update implementation of contains
1 parent 3c9125b commit fe9950e

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

priv/std_lib/bootstrap/functions.ex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ defmodule ElixirScript.Bootstrap.Functions do
55
end
66

77
def contains(left, [right]) do
8-
match?(left, right)
8+
case right do
9+
^left ->
10+
true
11+
_ ->
12+
false
13+
end
914
end
1015

11-
def contains(left, [h|t]) do
12-
case match?(left, h) do
13-
true ->
16+
def contains(left, [h|t]) do
17+
case h do
18+
^left ->
1419
true
15-
false ->
20+
_ ->
1621
contains(left, t)
1722
end
1823
end

test/app/spec/bootstrap/functions.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ describe('Functions', () => {
66
const Functions = Elixir.load(Elixir.ElixirScript.Bootstrap.Functions);
77
expect(Functions.contains(1, [])).to.eq(false);
88
expect(Functions.contains(1, [1, 2, 3])).to.eq(true);
9+
expect(Functions.contains(4, [1, 2, 3])).to.eq(false);
910
expect(Functions.contains(1, [1])).to.eq(true);
10-
11+
expect(Functions.contains(4, [1])).to.eq(false);
1112
expect(Functions.contains('apple', [1])).to.eq(false);
1213
});
1314

@@ -16,7 +17,7 @@ describe('Functions', () => {
1617
expect(Functions.get_object_keys({})).to.eql([]);
1718
expect(Functions.get_object_keys({ key: 1 })).to.eql(['key']);
1819
expect(
19-
Functions.get_object_keys({ key: 1, [Symbol.for('hi')]: 2 }),
20+
Functions.get_object_keys({ key: 1, [Symbol.for('hi')]: 2 })
2021
).to.eql(['key', Symbol.for('hi')]);
2122
});
2223

0 commit comments

Comments
 (0)