[Solved] Arrays to objects
Some diversity of approaches (admittedly esoteric, but fun!): function firstAndLast(a, o){ return !(o = {}, o[a.shift()] = a.pop()) || o; } console.log(firstAndLast([1,2,3,4,5])); console.log(firstAndLast([‘a’,’to’,’z’])); https://jsfiddle.net/brtsbLp1/ And, of course: function firstAndLast(a, o){ return !(o = o || {}, o[a.shift()] = a.pop()) || o; } console.log(firstAndLast([‘a’,’to’,’z’])); console.log(firstAndLast([‘a’,’to’,’z’], {a:’nother’,obj:’ect’})); https://jsfiddle.net/brtsbLp1/1/ Another fun one: function firstAndLast(a){ return JSON.parse(‘{“‘+a.shift()+'”:”‘+a.pop()+'”}’); } https://jsfiddle.net/brtsbLp1/2/ … Read more