Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //06.Equal Sums
- function equalSums(arr) {
- for (let i = 0; i < arr.length; i++)
- if (isEqual(arr, i)) {
- console.log(i)
- return
- }
- console.log('no')
- function isEqual(arr, index) {
- let leftSum = 0
- let rightSum = 0
- for (let i = 0; i < index; i++)
- leftSum += arr[i]
- for (let i = index + 1; i < arr.length; i++)
- rightSum += arr[i]
- if (leftSum === rightSum)
- return true
- else
- return false
- }
- }
- equalSums0([1, 2, 3, 3])
- const update = function (x, y) {
- // Do something with x and y
- };
- function equalSums0(arr) {
- 'use strict'
- const isEqual0 = function (arr, index) {
- let leftSum = 0
- let rightSum = 0
- for (let i = 0; i < index; i++)
- leftSum += arr[i]
- for (let i = index + 1; i < arr.length; i++)
- rightSum += arr[i]
- return (leftSum === rightSum) ? true : false
- }
- for (let i = 0; i < arr.length; i++)
- if (isEqual0(arr, i)) {
- console.log(i)
- return
- }
- console.log('no')
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement