Yes, there is a better way: Math.abs().
More Related Contents:
- Cartesian product of multiple arrays in JavaScript
- Javascript Array.sort implementation?
- Finding All Combinations (Cartesian product) of JavaScript array values
- Fast stable sorting algorithm implementation in javascript
- How does this recursion work?
- Improving performance of click detection on a staggered column isometric grid
- How do I sort an array of objects based on the ordering of another array?
- Efficient way to insert a number into a sorted array of numbers?
- Fastest way to flatten / un-flatten nested JavaScript objects
- Recursively print all permutations of a string (Javascript)
- Where is my implementation of rot13 in JavaScript going wrong?
- Bresenham algorithm in Javascript
- Permutations without recursive function call
- Packing different sized circles into rectangle – d3.js
- Using Canvas to animate a sorting algorithm in JS
- Sorting Array with JavaScript reduce function
- Find difference between two strings in JavaScript
- Check if polygon is inside a polygon
- Remove duplicate objects from an array using javascript
- Solving TicTacToe with minimax algorithm in Javascript
- Combine json arrays by key, javascript
- How to find horizon line efficiently in a high-altitude photo?
- Number.sign() in javascript
- 3D point rotation algorithm
- Creating an array consisting of the largest values of each sub-array does not work as expected
- Given an array, how to generate all combinations of subset size k?
- Two-sum Leetcode explanation, Hashmap, Javascript
- Diamond-square algorithm not working (rewrite code from JS to JAVA)
- Visualization of calendar events. Algorithm to layout events with maximum width
- Algorithm of JavaScript “sort()” Function