Skip to content

Instantly share code, notes, and snippets.

@diogovk
Created June 26, 2014 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogovk/22f35fd8a0a34aedaeaf to your computer and use it in GitHub Desktop.
Save diogovk/22f35fd8a0a34aedaeaf to your computer and use it in GitHub Desktop.
Elixir -> javascript Challenge
iex(1)> l = [1, 2, 3]
#=> [1, 2, 3]
iex(2)> l2 = tl(l)
#=> [2, 3]
iex(3)> l2 = [ 0 | l2 ]
#=> [0, 2, 3]
iex(4)> IO.inspect l
[1, 2, 3]
#=> [1, 2, 3]
iex(5)> IO.inspect l2
[0, 2, 3]
#=> [0, 2, 3]
# IO.inspect and IO.puts should use to console.log()
@marcioj
Copy link

marcioj commented Jun 26, 2014

#!/usr/bin/env node

function tl(l) {
  return l.slice(1, l.length);
}
function prepend(elem, array) {
  var copy = array.slice();
  copy.unshift(elem);
  return copy;
}

var l = [1,2,3];
var l2 = tl(l);
l2 = prepend(0, l2);
console.log(l);
console.log(l2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment