如何在另一个函数中的函数内部使用数组中的值?

时间:2018-12-02 18:03:29

标签: javascript arrays function binary

我用Javascript创建了一个将十进制数转换为二进制数的函数,并使用一个数组存储二进制数,并使该函数返回该数组,我想要的是,如何获取该数组的值,以及在功能之外还是其他功能中使用它?

多数民众赞成在我正在谈论的功能,而我想要的数组称为numArray。

body {
  background-color: #FFF;
  margin: 0 auto;
}

header {
  background-color: #466995;
  border-bottom: 1px solid #466995;
  position: absolute; // This line!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  border: thin solid red !important;
}

ul {
  margin: 30px auto;
  padding: 0 20px;
  text-align: center;
}

li {
  color: #FFF;
  font-family: 'Oswald', sans-serif;
  font-size: 16px;
  font-weight: 300;
  text-transform: uppercase;
}

li:hover {
  color: #DBE9EE;
}

h1 {
  color: #466995;
  font-family: 'Oswald', sans-serif;
  font-size: 32px;
  font-weight: 300;
  text-transform: uppercase;
}

h2 {
  color: #333;
  font-family: 'Varela Round', sans-serif;
  font-size: 26px;
  font-weight: 100;
  margin: 0 auto 20px auto;
}

h3 {
  color: #466995;
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  padding: 30px;
}

h4 {
  color: #466995;
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  font-weight: 300;
  letter-spacing: 2px;
  text-align: center;
  text-transform: uppercase
}

p {
  color: #333;
  font-family: 'Varela Round', sans-serif;
  font-size: 18px;
}

footer {
  background-color: #DBE9EE;
  text-align: center;
}

.welcome {
  background-color: #DBE9EE;
  box-sizing: border-box;
  padding: 40px;
  text-align: center;
  width: 100%;
}

.question {
  text-align: center;
  position: relative;
  top: 40px;
}

.answer {
  border: 1px solid #466995;
  margin: 20px;
}

.answer:hover {
  background: #C0D6DF;
  color: #FFF;
}

1 个答案:

答案 0 :(得分:-1)

public static partial class EnumerableExtensions
{
    public static bool IfNonEmpty<T>(this IEnumerable<T> source, Action<IEnumerable<T>> func)
    {
        if (source == null|| func == null)
            throw new ArgumentNullException();
        using (var enumerator = source.GetEnumerator())
        {
            if (!enumerator.MoveNext())
                return false;
            func(new UsedEnumerator<T>(enumerator));
            return true;
        }
    }

    class UsedEnumerator<T> : IEnumerable<T>
    {
        IEnumerator<T> usedEnumerator;

        public UsedEnumerator(IEnumerator<T> usedEnumerator)
        {
            if (usedEnumerator == null)
                throw new ArgumentNullException();
            this.usedEnumerator = usedEnumerator;
        }

        public IEnumerator<T> GetEnumerator()
        {
            var localEnumerator = System.Threading.Interlocked.Exchange(ref usedEnumerator, null);
            if (localEnumerator == null)
                // An attempt has been made to enumerate usedEnumerator more than once; 
                // throw an exception since this is not allowed.
                throw new InvalidOperationException();
            yield return localEnumerator.Current;
            while (localEnumerator.MoveNext())
            {
                yield return localEnumerator.Current;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}

PS:-这是反模式,如果您更新问题,我可以说出更多的解决方法。