Skip to content

Instantly share code, notes, and snippets.

@ybeliaev
Created September 11, 2018 16:42
Show Gist options
  • Save ybeliaev/88f3e7a305a0a6356d11fcca553ea26a to your computer and use it in GitHub Desktop.
Save ybeliaev/88f3e7a305a0a6356d11fcca553ea26a to your computer and use it in GitHub Desktop.
Google tasks 1 - 10 created by ybeliaev - https://repl.it/@ybeliaev/Google-tasks-1-10
// 1. GOOGLE. Given a list of numbers and a number k, return whether any two numbers from the list add up to k.
// For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
function checkArrForNumber(arr, k){
var res;
for(var i = 0; i < arr.length; i++){
for(var j = 1; j < arr.length; j++){
res = arr[i] + arr[j];
if(res == k){
return true;
}
}
}
return false;// объясни почему тут место return а не в else после if
}
var arr1 = [10, 15, 3, 7];
//checkArrForNumber(arr1, 13)
//11111111111111111111111111111111111111111111111111111111111111111111111111111
// 2. UBER. Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i.
// For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6]. т.е. получаем произведение всех чисел и делим на arr[i] исходного массива
function getMultArray(arr){
let res = 1;
let newArr = [];
for(let i = 0; i < arr.length; i++){
res *= arr[i];
}
for(let i = 0; i < arr.length; i++){
newArr.push(res/arr[i]);
}
return newArr;
}
var arr2 = [1, 2, 3, 4, 5];
getMultArray(arr2)
//22222222222222222222222222222222222222222222222222222222222222222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment