diff --git a/js/easy/sorted_squared_array.js b/js/easy/sorted_squared_array.js new file mode 100644 index 0000000..baf03a2 --- /dev/null +++ b/js/easy/sorted_squared_array.js @@ -0,0 +1,8 @@ +// Square a sorted array and return it still sorted + +function sortedSquaredArray(array) { + for (let i = 0; i < array.length; i++) { + array[i] = array[i] * array[i] + } + return array.sort((a, b) => a - b) +}