{"size": 1308, "ext": "js", "max_stars_repo_path": "8-kyu/To square(root) or not to square(root)/index.js", "max_stars_repo_name": "ayessetova/codeW", "max_stars_repo_stars_event_min_datetime": "2017-12-08T16:51:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T01:59:49.000Z", "max_issues_repo_path": "8-kyu/To square(root) or not to square(root)/index.js", "max_issues_repo_name": "ayessetova/codeW", "max_issues_repo_issues_event_min_datetime": "2018-04-27T03:54:20.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-06T20:13:40.000Z", "max_forks_repo_path": "8-kyu/To square(root) or not to square(root)/index.js", "max_forks_repo_name": "ayessetova/codeW", "max_forks_repo_forks_event_min_datetime": "2017-12-18T18:19:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T12:16:38.000Z"}
{"max_stars_count": 314, "max_issues_count": 4, "max_forks_count": 141, "avg_line_length": 29.7272727273, "max_line_length": 110, "alphanum_fraction": 0.7171253823}
/*
  Title:
    To square(root) or not to square(root)

  Description:
    #To square(root) or not to square(root)

    Write a method, that will get an integer array as parameter and will process every number from this array.
    Return a new array with processing every number of the input-array like this:

    If the number has an integer square root, take this, otherwise square the number.

    [4,3,9,7,2,1] -> [2,9,3,49,4,1]
    The input array will always contain only positive numbers and will never be empty or null.

    The input array should not be modified!

    Have fun coding it and please don't forget to vote and rank this kata! :-)

    I have also created other katas. Take a look if you enjoyed this kata!

  Examples:

  Notes:

  Kata Link:
    https://www.codewars.com/kata/to-square-root-or-not-to-square-root

  Discuss Link:
    https://www.codewars.com/kata/to-square-root-or-not-to-square-root/discuss

  Solutions Link:
    https://www.codewars.com/kata/to-square-root-or-not-to-square-root/solutions
*/

// Long Solution
const isSquareRootInteger = number => Number.isInteger(Math.sqrt(number))

const squareOrSquareRoot = array =>
  array.map(number => (isSquareRootInteger(number) ? Math.sqrt(number) : number ** 2))

// Function Export
module.exports = squareOrSquareRoot
