Skip to content

Instantly share code, notes, and snippets.

@coderaiser
Last active August 29, 2015 14:07
Show Gist options
  • Save coderaiser/6196a09aeb9c3f4bbe0d to your computer and use it in GitHub Desktop.
Save coderaiser/6196a09aeb9c3f4bbe0d to your computer and use it in GitHub Desktop.
/* add spaces beetwen words
*
* "view f4" -> "view f4"
*/
function item(name, n) {
var str = '',
array = [],
spaces = [],
count = 0;
if (!n)
n = 21;
count = n - name.length;
spaces = new Array(count).join(' ');
array = name.split(' ');
str = array[array.length - 1];
str = name.replace(str, spaces + str);
return str;
}
/* travers an object */
function items(menu) {
var result = {};
Object.keys(menu)
.forEach(function(current) {
var isObj = Util.type.object(menu[current]),
name = item(current);
if (isObj)
result[name] = items(menu[current]);
else
result[name] = menu[current];
});
return result;
}
/* add spaces between name and keys size long
*
* 'view', 'F4' -> 'view F4'
*/
function item2(name, keys, size) {
var array, str;
Util.checkArgs(arguments, ['name']);
if (!keys) {
str = name;
} else {
if (!size)
size = 21;
array = new Array(21)
.join(' ')
.split('');
name.split('').forEach(function(char, i) {
array[i] = char;
});
array.reverse();
keys.split('')
.reverse('')
.forEach(function(key, i) {
array[i] = key;
});
str = array.reverse().join('');
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment