Compare keys of array in RUBY










-4















I have this structure:



$ArrayX = [8349310431,8349314513,......]
$ArrayY = [667984788,667987788,......]
$ArrayZ = [148507632380,153294624079,.....]

$range_map = $ArrayX.zip([$ArrayY.map(&:to_i),
$ArrayZ.map(&:to_i)].transpose).sort

puts $range_map =[8349310431=>[667984788, 148507632380],
8349314513=>[667987788, 153294624079]


I need the key to be compared with the rest of the keys and if the subtraction between keys is lower than 100, that key to print










share|improve this question



















  • 5





    Don't use $ for variables, provide correct arrays (currently they're empty), provide correct output (it's currently an array in hash, which just doesn't work).

    – Marcin Kołodziej
    Nov 14 '18 at 3:09











  • Your $range_map is an Array, not a Hash. It is still very unclear what you expect the output to be. If you provide a Minimal, Complete and Verifiable Example, you will receive a proper answer.

    – Marcin Kołodziej
    Nov 14 '18 at 3:29











  • Please don’t add unnecessary commentary in your question titles. If you really feel the need to apologize for the title then you haven’t spent enough time being thoughtful and should slow down before submitting your question. Please read stackoverflow.com/help/how-to-ask for more information on effective titles.

    – anothermh
    Nov 14 '18 at 5:44















-4















I have this structure:



$ArrayX = [8349310431,8349314513,......]
$ArrayY = [667984788,667987788,......]
$ArrayZ = [148507632380,153294624079,.....]

$range_map = $ArrayX.zip([$ArrayY.map(&:to_i),
$ArrayZ.map(&:to_i)].transpose).sort

puts $range_map =[8349310431=>[667984788, 148507632380],
8349314513=>[667987788, 153294624079]


I need the key to be compared with the rest of the keys and if the subtraction between keys is lower than 100, that key to print










share|improve this question



















  • 5





    Don't use $ for variables, provide correct arrays (currently they're empty), provide correct output (it's currently an array in hash, which just doesn't work).

    – Marcin Kołodziej
    Nov 14 '18 at 3:09











  • Your $range_map is an Array, not a Hash. It is still very unclear what you expect the output to be. If you provide a Minimal, Complete and Verifiable Example, you will receive a proper answer.

    – Marcin Kołodziej
    Nov 14 '18 at 3:29











  • Please don’t add unnecessary commentary in your question titles. If you really feel the need to apologize for the title then you haven’t spent enough time being thoughtful and should slow down before submitting your question. Please read stackoverflow.com/help/how-to-ask for more information on effective titles.

    – anothermh
    Nov 14 '18 at 5:44













-4












-4








-4








I have this structure:



$ArrayX = [8349310431,8349314513,......]
$ArrayY = [667984788,667987788,......]
$ArrayZ = [148507632380,153294624079,.....]

$range_map = $ArrayX.zip([$ArrayY.map(&:to_i),
$ArrayZ.map(&:to_i)].transpose).sort

puts $range_map =[8349310431=>[667984788, 148507632380],
8349314513=>[667987788, 153294624079]


I need the key to be compared with the rest of the keys and if the subtraction between keys is lower than 100, that key to print










share|improve this question
















I have this structure:



$ArrayX = [8349310431,8349314513,......]
$ArrayY = [667984788,667987788,......]
$ArrayZ = [148507632380,153294624079,.....]

$range_map = $ArrayX.zip([$ArrayY.map(&:to_i),
$ArrayZ.map(&:to_i)].transpose).sort

puts $range_map =[8349310431=>[667984788, 148507632380],
8349314513=>[667987788, 153294624079]


I need the key to be compared with the rest of the keys and if the subtraction between keys is lower than 100, that key to print







ruby hash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 5:40









anothermh

3,26831632




3,26831632










asked Nov 14 '18 at 3:04









Alejandro RodriguezAlejandro Rodriguez

64




64







  • 5





    Don't use $ for variables, provide correct arrays (currently they're empty), provide correct output (it's currently an array in hash, which just doesn't work).

    – Marcin Kołodziej
    Nov 14 '18 at 3:09











  • Your $range_map is an Array, not a Hash. It is still very unclear what you expect the output to be. If you provide a Minimal, Complete and Verifiable Example, you will receive a proper answer.

    – Marcin Kołodziej
    Nov 14 '18 at 3:29











  • Please don’t add unnecessary commentary in your question titles. If you really feel the need to apologize for the title then you haven’t spent enough time being thoughtful and should slow down before submitting your question. Please read stackoverflow.com/help/how-to-ask for more information on effective titles.

    – anothermh
    Nov 14 '18 at 5:44












  • 5





    Don't use $ for variables, provide correct arrays (currently they're empty), provide correct output (it's currently an array in hash, which just doesn't work).

    – Marcin Kołodziej
    Nov 14 '18 at 3:09











  • Your $range_map is an Array, not a Hash. It is still very unclear what you expect the output to be. If you provide a Minimal, Complete and Verifiable Example, you will receive a proper answer.

    – Marcin Kołodziej
    Nov 14 '18 at 3:29











  • Please don’t add unnecessary commentary in your question titles. If you really feel the need to apologize for the title then you haven’t spent enough time being thoughtful and should slow down before submitting your question. Please read stackoverflow.com/help/how-to-ask for more information on effective titles.

    – anothermh
    Nov 14 '18 at 5:44







5




5





Don't use $ for variables, provide correct arrays (currently they're empty), provide correct output (it's currently an array in hash, which just doesn't work).

– Marcin Kołodziej
Nov 14 '18 at 3:09





Don't use $ for variables, provide correct arrays (currently they're empty), provide correct output (it's currently an array in hash, which just doesn't work).

– Marcin Kołodziej
Nov 14 '18 at 3:09













Your $range_map is an Array, not a Hash. It is still very unclear what you expect the output to be. If you provide a Minimal, Complete and Verifiable Example, you will receive a proper answer.

– Marcin Kołodziej
Nov 14 '18 at 3:29





Your $range_map is an Array, not a Hash. It is still very unclear what you expect the output to be. If you provide a Minimal, Complete and Verifiable Example, you will receive a proper answer.

– Marcin Kołodziej
Nov 14 '18 at 3:29













Please don’t add unnecessary commentary in your question titles. If you really feel the need to apologize for the title then you haven’t spent enough time being thoughtful and should slow down before submitting your question. Please read stackoverflow.com/help/how-to-ask for more information on effective titles.

– anothermh
Nov 14 '18 at 5:44





Please don’t add unnecessary commentary in your question titles. If you really feel the need to apologize for the title then you haven’t spent enough time being thoughtful and should slow down before submitting your question. Please read stackoverflow.com/help/how-to-ask for more information on effective titles.

– anothermh
Nov 14 '18 at 5:44












1 Answer
1






active

oldest

votes


















0














I corrected your code also as per your need, and solved further,



$ArrayX = [8349310431,8349314513]
$ArrayY = [667984788,667987788]
$ArrayZ = [148507632380,153294624079]

$range_map = $ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort

$ArrayX = [8349310431,8349314513]
=> [8349310431, 8349314513]
$ArrayY = [667984788,667987788]
=> [667984788, 667987788]
$ArrayZ = [148507632380,153294624079]
=> [148507632380, 153294624079]

$range_map = Hash[$ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort]
=> 8349310431=>[667984788, 148507632380], 8349314513=>[667987788, 153294624079]

keys = $range_map.keys
valid_keys = keys.select k
$range_map.slice(*valid_keys)


If particular key is having difference more than 100 with one of rest of keys then it will be valid for filtering.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292598%2fcompare-keys-of-array-in-ruby%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I corrected your code also as per your need, and solved further,



    $ArrayX = [8349310431,8349314513]
    $ArrayY = [667984788,667987788]
    $ArrayZ = [148507632380,153294624079]

    $range_map = $ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort

    $ArrayX = [8349310431,8349314513]
    => [8349310431, 8349314513]
    $ArrayY = [667984788,667987788]
    => [667984788, 667987788]
    $ArrayZ = [148507632380,153294624079]
    => [148507632380, 153294624079]

    $range_map = Hash[$ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort]
    => 8349310431=>[667984788, 148507632380], 8349314513=>[667987788, 153294624079]

    keys = $range_map.keys
    valid_keys = keys.select k
    $range_map.slice(*valid_keys)


    If particular key is having difference more than 100 with one of rest of keys then it will be valid for filtering.






    share|improve this answer



























      0














      I corrected your code also as per your need, and solved further,



      $ArrayX = [8349310431,8349314513]
      $ArrayY = [667984788,667987788]
      $ArrayZ = [148507632380,153294624079]

      $range_map = $ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort

      $ArrayX = [8349310431,8349314513]
      => [8349310431, 8349314513]
      $ArrayY = [667984788,667987788]
      => [667984788, 667987788]
      $ArrayZ = [148507632380,153294624079]
      => [148507632380, 153294624079]

      $range_map = Hash[$ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort]
      => 8349310431=>[667984788, 148507632380], 8349314513=>[667987788, 153294624079]

      keys = $range_map.keys
      valid_keys = keys.select k
      $range_map.slice(*valid_keys)


      If particular key is having difference more than 100 with one of rest of keys then it will be valid for filtering.






      share|improve this answer

























        0












        0








        0







        I corrected your code also as per your need, and solved further,



        $ArrayX = [8349310431,8349314513]
        $ArrayY = [667984788,667987788]
        $ArrayZ = [148507632380,153294624079]

        $range_map = $ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort

        $ArrayX = [8349310431,8349314513]
        => [8349310431, 8349314513]
        $ArrayY = [667984788,667987788]
        => [667984788, 667987788]
        $ArrayZ = [148507632380,153294624079]
        => [148507632380, 153294624079]

        $range_map = Hash[$ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort]
        => 8349310431=>[667984788, 148507632380], 8349314513=>[667987788, 153294624079]

        keys = $range_map.keys
        valid_keys = keys.select k
        $range_map.slice(*valid_keys)


        If particular key is having difference more than 100 with one of rest of keys then it will be valid for filtering.






        share|improve this answer













        I corrected your code also as per your need, and solved further,



        $ArrayX = [8349310431,8349314513]
        $ArrayY = [667984788,667987788]
        $ArrayZ = [148507632380,153294624079]

        $range_map = $ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort

        $ArrayX = [8349310431,8349314513]
        => [8349310431, 8349314513]
        $ArrayY = [667984788,667987788]
        => [667984788, 667987788]
        $ArrayZ = [148507632380,153294624079]
        => [148507632380, 153294624079]

        $range_map = Hash[$ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort]
        => 8349310431=>[667984788, 148507632380], 8349314513=>[667987788, 153294624079]

        keys = $range_map.keys
        valid_keys = keys.select k
        $range_map.slice(*valid_keys)


        If particular key is having difference more than 100 with one of rest of keys then it will be valid for filtering.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 5:30









        rayray

        2,3891623




        2,3891623



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292598%2fcompare-keys-of-array-in-ruby%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3