Skip to content

Instantly share code, notes, and snippets.

@dab
Created April 4, 2018 09:13
Show Gist options
  • Save dab/f10732d82033311a5e1382b16b483d07 to your computer and use it in GitHub Desktop.
Save dab/f10732d82033311a5e1382b16b483d07 to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
const arg1 ={
"key1": "veryverylongvalue",
"key2": "longvalue",
"key3": "short"
}
const arg2 = 2
function jsonToArray(arg1, arg2) {
let arr = []
Object.keys(arg1).forEach(key => {
arr.push(arg1[key])
})
const result = arr.sort((a, b) => (a.length > b.length)).slice(0, arg2)
console.log(result)
return result
}
jsonToArray(arg1, arg2)
</script>
<script id="jsbin-source-javascript" type="text/javascript">const arg1 ={
"key1": "veryverylongvalue",
"key2": "longvalue",
"key3": "short"
}
const arg2 = 2
function jsonToArray(arg1, arg2) {
let arr = []
Object.keys(arg1).forEach(key => {
arr.push(arg1[key])
})
const result = arr.sort((a, b) => (a.length > b.length)).slice(0, arg2)
console.log(result)
return result
}
jsonToArray(arg1, arg2)
</script></body>
</html>
const arg1 ={
"key1": "veryverylongvalue",
"key2": "longvalue",
"key3": "short"
}
const arg2 = 2
function jsonToArray(arg1, arg2) {
let arr = []
Object.keys(arg1).forEach(key => {
arr.push(arg1[key])
})
const result = arr.sort((a, b) => (a.length > b.length)).slice(0, arg2)
console.log(result)
return result
}
jsonToArray(arg1, arg2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment