Function to determine the direction of an arrow











up vote
1
down vote

favorite
1












I have a function in a project that I feel could be written better. The purpose of the function is to return the direction of an arrow based on two parameters.





  • positiveDirection: The direction for a positive result. The values could be increasing or decreasing.


  • changeType: Whether the result was positive, negative or no-change.


I guess it's the if statement that is bothering me the most; it looks like it could be reduced based on some logic gate that I don't know of.






  getArrowDirection = (positiveDirection, changeType) => {

let direction = null

if(changeType === 'no-change') {
return direction
}

if(
(changeType === 'positive' && positiveDirection === 'increasing') ||
(changeType === 'negative' && positiveDirection === 'decreasing')
) {
direction = 'up-arrow'
} else if(
(changeType === 'positive' && positiveDirection === 'decreasing') ||
(changeType === 'negative' && positiveDirection === 'increasing')
) {
direction = 'down-arrow'
}

return direction
}












share|improve this question
























  • What's possible values for changeValue and positiveDirection?
    – Calak
    2 days ago












  • We might be able to improve the code further if we knew the context. Who calls this code, and where do the parameter values come from?
    – 200_success
    2 days ago















up vote
1
down vote

favorite
1












I have a function in a project that I feel could be written better. The purpose of the function is to return the direction of an arrow based on two parameters.





  • positiveDirection: The direction for a positive result. The values could be increasing or decreasing.


  • changeType: Whether the result was positive, negative or no-change.


I guess it's the if statement that is bothering me the most; it looks like it could be reduced based on some logic gate that I don't know of.






  getArrowDirection = (positiveDirection, changeType) => {

let direction = null

if(changeType === 'no-change') {
return direction
}

if(
(changeType === 'positive' && positiveDirection === 'increasing') ||
(changeType === 'negative' && positiveDirection === 'decreasing')
) {
direction = 'up-arrow'
} else if(
(changeType === 'positive' && positiveDirection === 'decreasing') ||
(changeType === 'negative' && positiveDirection === 'increasing')
) {
direction = 'down-arrow'
}

return direction
}












share|improve this question
























  • What's possible values for changeValue and positiveDirection?
    – Calak
    2 days ago












  • We might be able to improve the code further if we knew the context. Who calls this code, and where do the parameter values come from?
    – 200_success
    2 days ago













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I have a function in a project that I feel could be written better. The purpose of the function is to return the direction of an arrow based on two parameters.





  • positiveDirection: The direction for a positive result. The values could be increasing or decreasing.


  • changeType: Whether the result was positive, negative or no-change.


I guess it's the if statement that is bothering me the most; it looks like it could be reduced based on some logic gate that I don't know of.






  getArrowDirection = (positiveDirection, changeType) => {

let direction = null

if(changeType === 'no-change') {
return direction
}

if(
(changeType === 'positive' && positiveDirection === 'increasing') ||
(changeType === 'negative' && positiveDirection === 'decreasing')
) {
direction = 'up-arrow'
} else if(
(changeType === 'positive' && positiveDirection === 'decreasing') ||
(changeType === 'negative' && positiveDirection === 'increasing')
) {
direction = 'down-arrow'
}

return direction
}












share|improve this question















I have a function in a project that I feel could be written better. The purpose of the function is to return the direction of an arrow based on two parameters.





  • positiveDirection: The direction for a positive result. The values could be increasing or decreasing.


  • changeType: Whether the result was positive, negative or no-change.


I guess it's the if statement that is bothering me the most; it looks like it could be reduced based on some logic gate that I don't know of.






  getArrowDirection = (positiveDirection, changeType) => {

let direction = null

if(changeType === 'no-change') {
return direction
}

if(
(changeType === 'positive' && positiveDirection === 'increasing') ||
(changeType === 'negative' && positiveDirection === 'decreasing')
) {
direction = 'up-arrow'
} else if(
(changeType === 'positive' && positiveDirection === 'decreasing') ||
(changeType === 'negative' && positiveDirection === 'increasing')
) {
direction = 'down-arrow'
}

return direction
}








  getArrowDirection = (positiveDirection, changeType) => {

let direction = null

if(changeType === 'no-change') {
return direction
}

if(
(changeType === 'positive' && positiveDirection === 'increasing') ||
(changeType === 'negative' && positiveDirection === 'decreasing')
) {
direction = 'up-arrow'
} else if(
(changeType === 'positive' && positiveDirection === 'decreasing') ||
(changeType === 'negative' && positiveDirection === 'increasing')
) {
direction = 'down-arrow'
}

return direction
}





  getArrowDirection = (positiveDirection, changeType) => {

let direction = null

if(changeType === 'no-change') {
return direction
}

if(
(changeType === 'positive' && positiveDirection === 'increasing') ||
(changeType === 'negative' && positiveDirection === 'decreasing')
) {
direction = 'up-arrow'
} else if(
(changeType === 'positive' && positiveDirection === 'decreasing') ||
(changeType === 'negative' && positiveDirection === 'increasing')
) {
direction = 'down-arrow'
}

return direction
}






javascript ecmascript-6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Toby Speight

22.4k537109




22.4k537109










asked 2 days ago









Richard Healy

364




364












  • What's possible values for changeValue and positiveDirection?
    – Calak
    2 days ago












  • We might be able to improve the code further if we knew the context. Who calls this code, and where do the parameter values come from?
    – 200_success
    2 days ago


















  • What's possible values for changeValue and positiveDirection?
    – Calak
    2 days ago












  • We might be able to improve the code further if we knew the context. Who calls this code, and where do the parameter values come from?
    – 200_success
    2 days ago
















What's possible values for changeValue and positiveDirection?
– Calak
2 days ago






What's possible values for changeValue and positiveDirection?
– Calak
2 days ago














We might be able to improve the code further if we knew the context. Who calls this code, and where do the parameter values come from?
– 200_success
2 days ago




We might be able to improve the code further if we knew the context. Who calls this code, and where do the parameter values come from?
– 200_success
2 days ago










4 Answers
4






active

oldest

votes

















up vote
2
down vote



accepted










If changeValue can only be (after your early check for 'no-change') equal to 'positive' or 'negative' and positiveDirection can only be equal to 'increasing' or 'decreasing, your if should cover all possible ways.



But you can simplify it a lot making use of the xor operator:



 direction = (changeType === 'positive' ^ positiveDirection === 'decreasing')
? 'up-arrow'
: 'down-arrow';


Or make the whole function a one-liner:



return (changeType !== 'no-change')
? ((changeType === 'positive' ^ positiveDirection === 'decreasing') ? 'up-arrow' : 'down-arrow')
: null;





share|improve this answer





















  • This is slick. Definitely a better solution than my original code. The ^ syntax was something I didn't know about.
    – Richard Healy
    2 days ago










  • Given A^B, if A and B are either both true or false, returns false. Otherwise, returns true. If fact, you can also replace it with != but I found the logic xor prettier/smarter :)
    – Calak
    2 days ago


















up vote
4
down vote













The test for if(changeType === 'no-change') { is redundant and not needed as it will fall through if the other tests fail and return null anyways.



You could also break the statement up returning the result as needed and falling through if they fail for null.



const getArrowDirection = (dir, type) => {
if (type === "positive") {
if (dir === "increasing") { return "up-arrow" }
if (dir === "decreasing") { return "down-arrow" }
}else if (type === "negative") {
if (dir === "increasing") { return "down-arrow" }
if (dir === "decreasing") { return "up-arrow" }
}
return null;
}


Assuming that you have given all possible values you can make assumptions and reduce the code further



const getArrowDirection = (dir, type) => {
if (type !== 'no-change') {
if (type === "positive") { return dir === "increasing" ? "up-arrow" : "down-arrow" }
return dir === "increasing" ? "down-arrow" : "up-arrow";
}
return null; // returning null is not the best. Returning undefined would
// be better and would not need this line
}


You can use an object as a lookup using the combined strings.



const getArrowDirection = (() => {
const directions = {
positiveincreasing: "up-arrow",
negativedecreasing: "up-arrow",
positivedecreasing: "down-arrow",
negativeincreasing: "down-arrow",
};
return (dir, type) => directions[type + dir] ? directions[type + dir] : null;
})();





share|improve this answer






























    up vote
    2
    down vote













    We don't need the direction variable - we can simply return at the appropriate point.



    Once you know that changeType is one of 'positive' or 'negative' and that positiveDirection is either 'increasing' or 'decreasing', you can test whether the two equality tests match:



    // Winging it, because this isn't my language!
    getArrowDirection = (positiveDirection, changeType) => {

    if (changeType != 'positive' && changeType != 'negative') {
    return null;
    }
    if (positiveDirection != 'increasing' && positiveDirection != 'decreasing')
    return null;
    }

    if ((changeType === 'positive') == (positiveDirection === 'increasing')) {
    return 'up-arrow';
    else
    return 'down-arrow';
    }
    }





    share|improve this answer




























      up vote
      0
      down vote













      You could could extract your conditions into functions with very clear condition description names. Would cut down the code because many of those conditions are repeated.






      share|improve this answer








      New contributor




      Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.


















        Your Answer





        StackExchange.ifUsing("editor", function () {
        return StackExchange.using("mathjaxEditing", function () {
        StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
        StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
        });
        });
        }, "mathjax-editing");

        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: "196"
        };
        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',
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        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%2fcodereview.stackexchange.com%2fquestions%2f208133%2ffunction-to-determine-the-direction-of-an-arrow%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote



        accepted










        If changeValue can only be (after your early check for 'no-change') equal to 'positive' or 'negative' and positiveDirection can only be equal to 'increasing' or 'decreasing, your if should cover all possible ways.



        But you can simplify it a lot making use of the xor operator:



         direction = (changeType === 'positive' ^ positiveDirection === 'decreasing')
        ? 'up-arrow'
        : 'down-arrow';


        Or make the whole function a one-liner:



        return (changeType !== 'no-change')
        ? ((changeType === 'positive' ^ positiveDirection === 'decreasing') ? 'up-arrow' : 'down-arrow')
        : null;





        share|improve this answer





















        • This is slick. Definitely a better solution than my original code. The ^ syntax was something I didn't know about.
          – Richard Healy
          2 days ago










        • Given A^B, if A and B are either both true or false, returns false. Otherwise, returns true. If fact, you can also replace it with != but I found the logic xor prettier/smarter :)
          – Calak
          2 days ago















        up vote
        2
        down vote



        accepted










        If changeValue can only be (after your early check for 'no-change') equal to 'positive' or 'negative' and positiveDirection can only be equal to 'increasing' or 'decreasing, your if should cover all possible ways.



        But you can simplify it a lot making use of the xor operator:



         direction = (changeType === 'positive' ^ positiveDirection === 'decreasing')
        ? 'up-arrow'
        : 'down-arrow';


        Or make the whole function a one-liner:



        return (changeType !== 'no-change')
        ? ((changeType === 'positive' ^ positiveDirection === 'decreasing') ? 'up-arrow' : 'down-arrow')
        : null;





        share|improve this answer





















        • This is slick. Definitely a better solution than my original code. The ^ syntax was something I didn't know about.
          – Richard Healy
          2 days ago










        • Given A^B, if A and B are either both true or false, returns false. Otherwise, returns true. If fact, you can also replace it with != but I found the logic xor prettier/smarter :)
          – Calak
          2 days ago













        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        If changeValue can only be (after your early check for 'no-change') equal to 'positive' or 'negative' and positiveDirection can only be equal to 'increasing' or 'decreasing, your if should cover all possible ways.



        But you can simplify it a lot making use of the xor operator:



         direction = (changeType === 'positive' ^ positiveDirection === 'decreasing')
        ? 'up-arrow'
        : 'down-arrow';


        Or make the whole function a one-liner:



        return (changeType !== 'no-change')
        ? ((changeType === 'positive' ^ positiveDirection === 'decreasing') ? 'up-arrow' : 'down-arrow')
        : null;





        share|improve this answer












        If changeValue can only be (after your early check for 'no-change') equal to 'positive' or 'negative' and positiveDirection can only be equal to 'increasing' or 'decreasing, your if should cover all possible ways.



        But you can simplify it a lot making use of the xor operator:



         direction = (changeType === 'positive' ^ positiveDirection === 'decreasing')
        ? 'up-arrow'
        : 'down-arrow';


        Or make the whole function a one-liner:



        return (changeType !== 'no-change')
        ? ((changeType === 'positive' ^ positiveDirection === 'decreasing') ? 'up-arrow' : 'down-arrow')
        : null;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Calak

        1,791214




        1,791214












        • This is slick. Definitely a better solution than my original code. The ^ syntax was something I didn't know about.
          – Richard Healy
          2 days ago










        • Given A^B, if A and B are either both true or false, returns false. Otherwise, returns true. If fact, you can also replace it with != but I found the logic xor prettier/smarter :)
          – Calak
          2 days ago


















        • This is slick. Definitely a better solution than my original code. The ^ syntax was something I didn't know about.
          – Richard Healy
          2 days ago










        • Given A^B, if A and B are either both true or false, returns false. Otherwise, returns true. If fact, you can also replace it with != but I found the logic xor prettier/smarter :)
          – Calak
          2 days ago
















        This is slick. Definitely a better solution than my original code. The ^ syntax was something I didn't know about.
        – Richard Healy
        2 days ago




        This is slick. Definitely a better solution than my original code. The ^ syntax was something I didn't know about.
        – Richard Healy
        2 days ago












        Given A^B, if A and B are either both true or false, returns false. Otherwise, returns true. If fact, you can also replace it with != but I found the logic xor prettier/smarter :)
        – Calak
        2 days ago




        Given A^B, if A and B are either both true or false, returns false. Otherwise, returns true. If fact, you can also replace it with != but I found the logic xor prettier/smarter :)
        – Calak
        2 days ago












        up vote
        4
        down vote













        The test for if(changeType === 'no-change') { is redundant and not needed as it will fall through if the other tests fail and return null anyways.



        You could also break the statement up returning the result as needed and falling through if they fail for null.



        const getArrowDirection = (dir, type) => {
        if (type === "positive") {
        if (dir === "increasing") { return "up-arrow" }
        if (dir === "decreasing") { return "down-arrow" }
        }else if (type === "negative") {
        if (dir === "increasing") { return "down-arrow" }
        if (dir === "decreasing") { return "up-arrow" }
        }
        return null;
        }


        Assuming that you have given all possible values you can make assumptions and reduce the code further



        const getArrowDirection = (dir, type) => {
        if (type !== 'no-change') {
        if (type === "positive") { return dir === "increasing" ? "up-arrow" : "down-arrow" }
        return dir === "increasing" ? "down-arrow" : "up-arrow";
        }
        return null; // returning null is not the best. Returning undefined would
        // be better and would not need this line
        }


        You can use an object as a lookup using the combined strings.



        const getArrowDirection = (() => {
        const directions = {
        positiveincreasing: "up-arrow",
        negativedecreasing: "up-arrow",
        positivedecreasing: "down-arrow",
        negativeincreasing: "down-arrow",
        };
        return (dir, type) => directions[type + dir] ? directions[type + dir] : null;
        })();





        share|improve this answer



























          up vote
          4
          down vote













          The test for if(changeType === 'no-change') { is redundant and not needed as it will fall through if the other tests fail and return null anyways.



          You could also break the statement up returning the result as needed and falling through if they fail for null.



          const getArrowDirection = (dir, type) => {
          if (type === "positive") {
          if (dir === "increasing") { return "up-arrow" }
          if (dir === "decreasing") { return "down-arrow" }
          }else if (type === "negative") {
          if (dir === "increasing") { return "down-arrow" }
          if (dir === "decreasing") { return "up-arrow" }
          }
          return null;
          }


          Assuming that you have given all possible values you can make assumptions and reduce the code further



          const getArrowDirection = (dir, type) => {
          if (type !== 'no-change') {
          if (type === "positive") { return dir === "increasing" ? "up-arrow" : "down-arrow" }
          return dir === "increasing" ? "down-arrow" : "up-arrow";
          }
          return null; // returning null is not the best. Returning undefined would
          // be better and would not need this line
          }


          You can use an object as a lookup using the combined strings.



          const getArrowDirection = (() => {
          const directions = {
          positiveincreasing: "up-arrow",
          negativedecreasing: "up-arrow",
          positivedecreasing: "down-arrow",
          negativeincreasing: "down-arrow",
          };
          return (dir, type) => directions[type + dir] ? directions[type + dir] : null;
          })();





          share|improve this answer

























            up vote
            4
            down vote










            up vote
            4
            down vote









            The test for if(changeType === 'no-change') { is redundant and not needed as it will fall through if the other tests fail and return null anyways.



            You could also break the statement up returning the result as needed and falling through if they fail for null.



            const getArrowDirection = (dir, type) => {
            if (type === "positive") {
            if (dir === "increasing") { return "up-arrow" }
            if (dir === "decreasing") { return "down-arrow" }
            }else if (type === "negative") {
            if (dir === "increasing") { return "down-arrow" }
            if (dir === "decreasing") { return "up-arrow" }
            }
            return null;
            }


            Assuming that you have given all possible values you can make assumptions and reduce the code further



            const getArrowDirection = (dir, type) => {
            if (type !== 'no-change') {
            if (type === "positive") { return dir === "increasing" ? "up-arrow" : "down-arrow" }
            return dir === "increasing" ? "down-arrow" : "up-arrow";
            }
            return null; // returning null is not the best. Returning undefined would
            // be better and would not need this line
            }


            You can use an object as a lookup using the combined strings.



            const getArrowDirection = (() => {
            const directions = {
            positiveincreasing: "up-arrow",
            negativedecreasing: "up-arrow",
            positivedecreasing: "down-arrow",
            negativeincreasing: "down-arrow",
            };
            return (dir, type) => directions[type + dir] ? directions[type + dir] : null;
            })();





            share|improve this answer














            The test for if(changeType === 'no-change') { is redundant and not needed as it will fall through if the other tests fail and return null anyways.



            You could also break the statement up returning the result as needed and falling through if they fail for null.



            const getArrowDirection = (dir, type) => {
            if (type === "positive") {
            if (dir === "increasing") { return "up-arrow" }
            if (dir === "decreasing") { return "down-arrow" }
            }else if (type === "negative") {
            if (dir === "increasing") { return "down-arrow" }
            if (dir === "decreasing") { return "up-arrow" }
            }
            return null;
            }


            Assuming that you have given all possible values you can make assumptions and reduce the code further



            const getArrowDirection = (dir, type) => {
            if (type !== 'no-change') {
            if (type === "positive") { return dir === "increasing" ? "up-arrow" : "down-arrow" }
            return dir === "increasing" ? "down-arrow" : "up-arrow";
            }
            return null; // returning null is not the best. Returning undefined would
            // be better and would not need this line
            }


            You can use an object as a lookup using the combined strings.



            const getArrowDirection = (() => {
            const directions = {
            positiveincreasing: "up-arrow",
            negativedecreasing: "up-arrow",
            positivedecreasing: "down-arrow",
            negativeincreasing: "down-arrow",
            };
            return (dir, type) => directions[type + dir] ? directions[type + dir] : null;
            })();






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered 2 days ago









            Blindman67

            6,5341521




            6,5341521






















                up vote
                2
                down vote













                We don't need the direction variable - we can simply return at the appropriate point.



                Once you know that changeType is one of 'positive' or 'negative' and that positiveDirection is either 'increasing' or 'decreasing', you can test whether the two equality tests match:



                // Winging it, because this isn't my language!
                getArrowDirection = (positiveDirection, changeType) => {

                if (changeType != 'positive' && changeType != 'negative') {
                return null;
                }
                if (positiveDirection != 'increasing' && positiveDirection != 'decreasing')
                return null;
                }

                if ((changeType === 'positive') == (positiveDirection === 'increasing')) {
                return 'up-arrow';
                else
                return 'down-arrow';
                }
                }





                share|improve this answer

























                  up vote
                  2
                  down vote













                  We don't need the direction variable - we can simply return at the appropriate point.



                  Once you know that changeType is one of 'positive' or 'negative' and that positiveDirection is either 'increasing' or 'decreasing', you can test whether the two equality tests match:



                  // Winging it, because this isn't my language!
                  getArrowDirection = (positiveDirection, changeType) => {

                  if (changeType != 'positive' && changeType != 'negative') {
                  return null;
                  }
                  if (positiveDirection != 'increasing' && positiveDirection != 'decreasing')
                  return null;
                  }

                  if ((changeType === 'positive') == (positiveDirection === 'increasing')) {
                  return 'up-arrow';
                  else
                  return 'down-arrow';
                  }
                  }





                  share|improve this answer























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    We don't need the direction variable - we can simply return at the appropriate point.



                    Once you know that changeType is one of 'positive' or 'negative' and that positiveDirection is either 'increasing' or 'decreasing', you can test whether the two equality tests match:



                    // Winging it, because this isn't my language!
                    getArrowDirection = (positiveDirection, changeType) => {

                    if (changeType != 'positive' && changeType != 'negative') {
                    return null;
                    }
                    if (positiveDirection != 'increasing' && positiveDirection != 'decreasing')
                    return null;
                    }

                    if ((changeType === 'positive') == (positiveDirection === 'increasing')) {
                    return 'up-arrow';
                    else
                    return 'down-arrow';
                    }
                    }





                    share|improve this answer












                    We don't need the direction variable - we can simply return at the appropriate point.



                    Once you know that changeType is one of 'positive' or 'negative' and that positiveDirection is either 'increasing' or 'decreasing', you can test whether the two equality tests match:



                    // Winging it, because this isn't my language!
                    getArrowDirection = (positiveDirection, changeType) => {

                    if (changeType != 'positive' && changeType != 'negative') {
                    return null;
                    }
                    if (positiveDirection != 'increasing' && positiveDirection != 'decreasing')
                    return null;
                    }

                    if ((changeType === 'positive') == (positiveDirection === 'increasing')) {
                    return 'up-arrow';
                    else
                    return 'down-arrow';
                    }
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 2 days ago









                    Toby Speight

                    22.4k537109




                    22.4k537109






















                        up vote
                        0
                        down vote













                        You could could extract your conditions into functions with very clear condition description names. Would cut down the code because many of those conditions are repeated.






                        share|improve this answer








                        New contributor




                        Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          up vote
                          0
                          down vote













                          You could could extract your conditions into functions with very clear condition description names. Would cut down the code because many of those conditions are repeated.






                          share|improve this answer








                          New contributor




                          Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.




















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            You could could extract your conditions into functions with very clear condition description names. Would cut down the code because many of those conditions are repeated.






                            share|improve this answer








                            New contributor




                            Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            You could could extract your conditions into functions with very clear condition description names. Would cut down the code because many of those conditions are repeated.







                            share|improve this answer








                            New contributor




                            Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered 2 days ago









                            Dave

                            1




                            1




                            New contributor




                            Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208133%2ffunction-to-determine-the-direction-of-an-arrow%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







                                Popular posts from this blog

                                Quarter-circle Tiles

                                build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                                Mont Emei