【问题标题】:How to optimize this kind of code如何优化这种代码
【发布时间】:2018-01-27 18:07:31
【问题描述】:

如何使用searchstring 和current_object 获得mark 和mary?我必须使用array_push 推送新的searchstring 和current_object 来创建新的输出,例如mark 和mary。

function get_suggestion_array_from_object(searchstring, current_object) {
  var suggestion_array = [];
  console.log(current_object);
}

var test_searchstring = 'Ma';
var test_current_object_string = '{"r":{"k":0,"y":0}}';

var test_current_object = JSON.parse(test_current_object_string);

get_suggestion_array_from_object(test_searchstring, test_current_object);

【问题讨论】:

  • 你为什么用'jquery'标记这个问题? test_current_object_string中的属性r,k,y是什么意思?
  • 请在 Code Review SE 上发布此内容。

标签: javascript trie


【解决方案1】:

我完全不确定你在问什么,但只是一个简单的优化是这样的:

与其编写 JSON 字符串然后将其解析为对象,不如立即写入该对象:

var test_current_object_string = '{"r":{"k":0,"y":0}}';
var test_current_object = JSON.parse(test_current_object_string);

进入:

var test_current_object = {r:{k:0, y:0}};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 2016-01-01
    • 2017-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多