var arr = [1, 10, 20, 7], n = 9; function get(arr, n) { var a = arr.filter(function (b) { return b > n }).reduce(function (b, c) { var d = b + c * c; return d }, 0); return a } alert(get(arr, n))