Message from JavaScript discussions

February 2018

— How to do something like this with javascript

— 

Language:

python3


Source:
l = [1,2,2,3,3,3,4,4]
def remove(the_list, x):
if x in the_list:
del l[the_list.index(x)]
return the_list

l = remove(l, 4)
print(l)


Result:
[1, 2, 2, 3, 3, 3, 4]

— What i need is things inside the remove method

— Delete one value in array by the value

— I got it

var index = the_list.indexOf(x)
if (index !== -1) the_list.splice(index, 1)

— Thanks

— Source:

let l = [1,2,2,3,3,3,4,4];

const remove = (list, x) =>
list.includes(x) &&
list.filter((_, y) =>
list.indexOf(x) !== y, 1);

l = remove(l, 4);


Result:
[ 1, 2, 2, 3, 3, 3, 4 ]

Message permanent page

— Slightly messy

— Ew semicolon ew

— Source:

let l = [1,2,2,3,3,3,4,4];

const remove = (list, x) =>
R.without([ x ], list);

l = remove(l, 4);


Result:
[ 1, 2, 2, 3, 3, 3 ]

Message permanent page

— Semicolons are sexy

— Where is R come from?