Created
April 4, 2018 09:13
-
-
Save dab/f10732d82033311a5e1382b16b483d07 to your computer and use it in GitHub Desktop.
// source https://jsbin.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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