Last active
August 29, 2015 14:04
-
-
Save meeDamian/2b6c3d87735b7eee71f4 to your computer and use it in GitHub Desktop.
change key:value to the list of [key, value]
This file contains hidden or 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
| transformer = (obj) -> [key, val] for own key, val of obj when "_" isnt key.charAt 0 |
This file contains hidden or 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
| var transformer, | |
| __hasProp = {}.hasOwnProperty; | |
| transformer = function(obj) { | |
| var key, val, _results; | |
| _results = []; | |
| for (key in obj) { | |
| if (!__hasProp.call(obj, key)) continue; | |
| val = obj[key]; | |
| if ("_" !== key.charAt(0)) { | |
| _results.push([key, val]); | |
| } | |
| } | |
| return _results; | |
| }; |
This file contains hidden or 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
| // IGNORE: helper functions | |
| var retardedHash = function(str) { | |
| return (typeof str === "string" && str.length>0) | |
| ? str.charAt(0) + str.length | |
| : null | |
| } | |
| // IMPORTANT | |
| var obj = { | |
| a: 7, | |
| b: "kakako", | |
| _name: "secret", | |
| name: function() { | |
| return retardedHash(this._name); | |
| }, | |
| 3: "lalala" | |
| }; | |
| console.log(transformer(obj)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment