Skip to content

Instantly share code, notes, and snippets.

@ety001
Created December 21, 2014 07:26
Show Gist options
  • Save ety001/e9f2dbbfded527b2e62b to your computer and use it in GitHub Desktop.
Save ety001/e9f2dbbfded527b2e62b to your computer and use it in GitHub Desktop.
var _data = {
web_title : 'test_web_title',
url : 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614',
url_hash : '3335cf59a624847a6638ce19c2b98b02',
comment_text : '<script>alert(123)</script>'
};
写一个算法,遍历_data,生成下面的结果.
Result:
{ web_title: 'test_web_title' }
-------
{ web_title: 'test_web_title',
url: 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614' }
-------
{ web_title: 'test_web_title',
url: 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614',
url_hash: '3335cf59a624847a6638ce19c2b98b02' }
-------
{ web_title: 'test_web_title',
url: 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614',
url_hash: '3335cf59a624847a6638ce19c2b98b02',
comment_text: '<script>alert(123)</script>' }
-------
{ url: 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614' }
-------
{ url: 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614',
url_hash: '3335cf59a624847a6638ce19c2b98b02' }
-------
{ url: 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614',
url_hash: '3335cf59a624847a6638ce19c2b98b02',
comment_text: '<script>alert(123)</script>' }
-------
{ url_hash: '3335cf59a624847a6638ce19c2b98b02' }
-------
{ url_hash: '3335cf59a624847a6638ce19c2b98b02',
comment_text: '<script>alert(123)</script>' }
-------
{ comment_text: '<script>alert(123)</script>' }
-------
@ety001
Copy link
Author

ety001 commented Dec 21, 2014

  var _data = {
    web_title : 'test_web_title',
    url : 'http%3A%2F%2Fwww.demohour.com%2Fprojects%2F351614',
    url_hash : '3335cf59a624847a6638ce19c2b98b02',
    comment_text : '<script>alert(123)</script>'
  };
  var MAX = 4;
  for(var i=1; i<=MAX; i++){
    for(var j=i; j<=MAX; j++){
      var _post = {};
      var curt = 1;
      for(var key in _data){
        if(curt>=i && curt<=j){
          _post[key] = _data[key];
        }
        curt++;
      }
      console.log(_post);
      console.log('---------');
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment