Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

square root numbers in array javascript

function squareOrSquareRoot(array) {
  return array.map(x => {
    const r = Math.sqrt(x);
    return (r % 1 == 0) ? r : (x*x);
  });  
}
 
PREVIOUS NEXT
Tagged: #square #root #numbers #array #javascript
ADD COMMENT
Topic
Name
8+7 =