본문 바로가기

FOR78

English beggars Description: Born a misinterpretation of this kata, your task here is pretty simple: given an array of values and an amount of beggars, you are supposed to return an array with the sum of what each beggar brings home, assuming they all take regular turns, from the first to the last. For example: [1,2,3,4,5] for 2 beggars will return a result of [9,6], as the first one takes [1,3,5], the second c.. 2022. 3. 16.
+1 Array Description: Given an array of integers of any length, return an array that has 1 added to the value represented by the array. the array can't be empty only non-negative, single digit integers are allowed Return nil (or your language's equivalent) for invalid inputs. Examples For example the array [2, 3, 9] equals 239, adding one would return the array [2, 4, 0]. [4, 3, 2, 5] would return [4, 3,.. 2022. 3. 15.
Count the divisors of a number Description: Count the number of divisors of a positive integer n. Random tests go up to n = 500000. Examples (input --> output) 4 --> 3 (1, 2, 4) 5 --> 2 (1, 5) 12 --> 6 (1, 2, 3, 4, 6, 12) 30 --> 8 (1, 2, 3, 5, 6, 10, 15, 30) Solution: 1. Repeat 'n' to generate numbers one after the other. 2. Check whether the generated numbers are divisible by 'n'. 3. Count the number of divisible numbers. fu.. 2022. 3. 12.
Maximum Length Difference Description: You are given two arrays a1 and a2 of strings. Each string is composed with letters from a to z. Let x be any string in the first array and y be any string in the second array. Find max(abs(length(x) − length(y))) If a1 and/or a2 are empty return -1 in each language except in Haskell (F#) where you will return Nothing (None). Example: a1 = ["hoqq", "bbllkw", "oox", "ejjuyyy", "plmii.. 2022. 3. 11.
JavaScript _ 'for문'으로 배열의 합을 구하는 방법 자바스크립트의 경우 배열의 합을 구하는 간단한 내장함수가 없는 것 같습니다. (파이썬 최고..) 라이브러리를 설치하거나 for문 혹은 reduce함수를 사용해야하는데 이번 글에서 for문으로 배열 합을 구하는 함수를 만들어 보겠습니다. 코드부터 볼까요? let a = [1,2,3,4,5]; function sum(a){ let sum = 0; for (let i of a){ sum += i; }; return sum; }; console.log(sum(a)) >>> 15 1. 함수 sum은 배열을 인자로 받습니다. 2. 배열로부터 요소를 뽑아 sum이라는 변수에 반복하여 더합니다. 3. sum 변수를 반환합니다. 이처럼 함수를 미리 작성해두면 Python의 sum() 처럼 배열 합계를 구하는데 사용할 수.. 2022. 3. 5.
Equal Sides Of An Array Description: You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return -1. For example: Let's say you are given the array {1,2,3,4,3,2,1}: Your function will return the index 3, because at the 3rd p.. 2022. 3. 5.