Skip to content

Instantly share code, notes, and snippets.

@nobeans
Last active October 28, 2016 03:50
Show Gist options
  • Save nobeans/e3ebaf59f624ea305398f26b005a193b to your computer and use it in GitHub Desktop.
Save nobeans/e3ebaf59f624ea305398f26b005a193b to your computer and use it in GitHub Desktop.
function test(array) {
return Array.isArray(array) ? array.shift() : undefined
}
console.log(test([1]));
console.log("" + test([1]));
console.log(test([1, 2, 3]));
console.log("" + test([1, 2, 3]));
console.log(test([]));
console.log("" + test([]));
console.log(test(undefined));
// 1
// 1
// 1
// 1
// undefined
// undefined
// undefined
//
// *** time: 0.19983 ***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment